@@ -77,7 +77,7 @@ cdef class IndexEngine:
7777 bint over_size_threshold
7878
7979 cdef:
80- bint unique, monotonic
80+ bint unique, monotonic_inc, monotonic_dec
8181 bint initialized, monotonic_check, unique_check
8282
8383 def __init__ (self , vgetter , n ):
@@ -89,7 +89,8 @@ cdef class IndexEngine:
8989 self .monotonic_check = 0
9090
9191 self .unique = 0
92- self .monotonic = 0
92+ self .monotonic_inc = 0
93+ self .monotonic_dec = 0
9394
9495 def __contains__ (self , object val ):
9596 self ._ensure_mapping_populated()
@@ -134,7 +135,7 @@ cdef class IndexEngine:
134135 if is_definitely_invalid_key(val):
135136 raise TypeError
136137
137- if self .over_size_threshold and self .is_monotonic :
138+ if self .over_size_threshold and self .is_monotonic_increasing :
138139 if not self .is_unique:
139140 return self ._get_loc_duplicates(val)
140141 values = self ._get_index_values()
@@ -158,7 +159,7 @@ cdef class IndexEngine:
158159 cdef:
159160 Py_ssize_t diff
160161
161- if self .is_monotonic :
162+ if self .is_monotonic_increasing :
162163 values = self ._get_index_values()
163164 left = values.searchsorted(val, side = ' left' )
164165 right = values.searchsorted(val, side = ' right' )
@@ -210,25 +211,35 @@ cdef class IndexEngine:
210211
211212 return self .unique == 1
212213
213- property is_monotonic :
214+ property is_monotonic_increasing :
214215
215216 def __get__ (self ):
216217 if not self .monotonic_check:
217218 self ._do_monotonic_check()
218219
219- return self .monotonic == 1
220+ return self .monotonic_inc == 1
221+
222+ property is_monotonic_decreasing :
223+
224+ def __get__ (self ):
225+ if not self .monotonic_check:
226+ self ._do_monotonic_check()
227+
228+ return self .monotonic_dec == 1
220229
221230 cdef inline _do_monotonic_check(self ):
222231 try :
223232 values = self ._get_index_values()
224- self .monotonic, unique = self ._call_monotonic(values)
233+ self .monotonic_inc, self .monotonic_dec, unique = \
234+ self ._call_monotonic(values)
225235
226236 if unique is not None :
227237 self .unique = unique
228238 self .unique_check = 1
229239
230240 except TypeError :
231- self .monotonic = 0
241+ self .monotonic_inc = 0
242+ self .monotonic_dec = 0
232243 self .monotonic_check = 1
233244
234245 cdef _get_index_values(self ):
@@ -345,7 +356,7 @@ cdef class Int64Engine(IndexEngine):
345356 return _hash.Int64HashTable(n)
346357
347358 def _call_monotonic (self , values ):
348- return algos.is_monotonic_int64(values)
359+ return algos.is_monotonic_int64(values, timelike = False )
349360
350361 def get_pad_indexer (self , other , limit = None ):
351362 return algos.pad_int64(self ._get_index_values(), other,
@@ -435,7 +446,7 @@ cdef class Float64Engine(IndexEngine):
435446 return result
436447
437448 def _call_monotonic (self , values ):
438- return algos.is_monotonic_float64(values)
449+ return algos.is_monotonic_float64(values, timelike = False )
439450
440451 def get_pad_indexer (self , other , limit = None ):
441452 return algos.pad_float64(self ._get_index_values(), other,
@@ -489,7 +500,7 @@ cdef class ObjectEngine(IndexEngine):
489500 return _hash.PyObjectHashTable(n)
490501
491502 def _call_monotonic (self , values ):
492- return algos.is_monotonic_object(values)
503+ return algos.is_monotonic_object(values, timelike = False )
493504
494505 def get_pad_indexer (self , other , limit = None ):
495506 return algos.pad_object(self ._get_index_values(), other,
@@ -506,7 +517,7 @@ cdef class DatetimeEngine(Int64Engine):
506517 return ' M8[ns]'
507518
508519 def __contains__ (self , object val ):
509- if self .over_size_threshold and self .is_monotonic :
520+ if self .over_size_threshold and self .is_monotonic_increasing :
510521 if not self .is_unique:
511522 return self ._get_loc_duplicates(val)
512523 values = self ._get_index_values()
@@ -521,15 +532,15 @@ cdef class DatetimeEngine(Int64Engine):
521532 return self .vgetter().view(' i8' )
522533
523534 def _call_monotonic (self , values ):
524- return algos.is_monotonic_int64(values)
535+ return algos.is_monotonic_int64(values, timelike = True )
525536
526537 cpdef get_loc(self , object val):
527538 if is_definitely_invalid_key(val):
528539 raise TypeError
529540
530541 # Welcome to the spaghetti factory
531542
532- if self .over_size_threshold and self .is_monotonic :
543+ if self .over_size_threshold and self .is_monotonic_increasing :
533544 if not self .is_unique:
534545 val = _to_i8(val)
535546 return self ._get_loc_duplicates(val)
0 commit comments