@@ -77,7 +77,7 @@ cdef class IndexEngine:
77
77
bint over_size_threshold
78
78
79
79
cdef:
80
- bint unique, monotonic
80
+ bint unique, monotonic_inc, monotonic_dec
81
81
bint initialized, monotonic_check, unique_check
82
82
83
83
def __init__ (self , vgetter , n ):
@@ -89,7 +89,8 @@ cdef class IndexEngine:
89
89
self .monotonic_check = 0
90
90
91
91
self .unique = 0
92
- self .monotonic = 0
92
+ self .monotonic_inc = 0
93
+ self .monotonic_dec = 0
93
94
94
95
def __contains__ (self , object val ):
95
96
self ._ensure_mapping_populated()
@@ -134,7 +135,7 @@ cdef class IndexEngine:
134
135
if is_definitely_invalid_key(val):
135
136
raise TypeError
136
137
137
- if self .over_size_threshold and self .is_monotonic :
138
+ if self .over_size_threshold and self .is_monotonic_increasing :
138
139
if not self .is_unique:
139
140
return self ._get_loc_duplicates(val)
140
141
values = self ._get_index_values()
@@ -158,7 +159,7 @@ cdef class IndexEngine:
158
159
cdef:
159
160
Py_ssize_t diff
160
161
161
- if self .is_monotonic :
162
+ if self .is_monotonic_increasing :
162
163
values = self ._get_index_values()
163
164
left = values.searchsorted(val, side = ' left' )
164
165
right = values.searchsorted(val, side = ' right' )
@@ -210,25 +211,35 @@ cdef class IndexEngine:
210
211
211
212
return self .unique == 1
212
213
213
- property is_monotonic :
214
+ property is_monotonic_increasing :
214
215
215
216
def __get__ (self ):
216
217
if not self .monotonic_check:
217
218
self ._do_monotonic_check()
218
219
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
220
229
221
230
cdef inline _do_monotonic_check(self ):
222
231
try :
223
232
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)
225
235
226
236
if unique is not None :
227
237
self .unique = unique
228
238
self .unique_check = 1
229
239
230
240
except TypeError :
231
- self .monotonic = 0
241
+ self .monotonic_inc = 0
242
+ self .monotonic_dec = 0
232
243
self .monotonic_check = 1
233
244
234
245
cdef _get_index_values(self ):
@@ -345,7 +356,7 @@ cdef class Int64Engine(IndexEngine):
345
356
return _hash.Int64HashTable(n)
346
357
347
358
def _call_monotonic (self , values ):
348
- return algos.is_monotonic_int64(values)
359
+ return algos.is_monotonic_int64(values, timelike = False )
349
360
350
361
def get_pad_indexer (self , other , limit = None ):
351
362
return algos.pad_int64(self ._get_index_values(), other,
@@ -435,7 +446,7 @@ cdef class Float64Engine(IndexEngine):
435
446
return result
436
447
437
448
def _call_monotonic (self , values ):
438
- return algos.is_monotonic_float64(values)
449
+ return algos.is_monotonic_float64(values, timelike = False )
439
450
440
451
def get_pad_indexer (self , other , limit = None ):
441
452
return algos.pad_float64(self ._get_index_values(), other,
@@ -489,7 +500,7 @@ cdef class ObjectEngine(IndexEngine):
489
500
return _hash.PyObjectHashTable(n)
490
501
491
502
def _call_monotonic (self , values ):
492
- return algos.is_monotonic_object(values)
503
+ return algos.is_monotonic_object(values, timelike = False )
493
504
494
505
def get_pad_indexer (self , other , limit = None ):
495
506
return algos.pad_object(self ._get_index_values(), other,
@@ -506,7 +517,7 @@ cdef class DatetimeEngine(Int64Engine):
506
517
return ' M8[ns]'
507
518
508
519
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 :
510
521
if not self .is_unique:
511
522
return self ._get_loc_duplicates(val)
512
523
values = self ._get_index_values()
@@ -521,15 +532,15 @@ cdef class DatetimeEngine(Int64Engine):
521
532
return self .vgetter().view(' i8' )
522
533
523
534
def _call_monotonic (self , values ):
524
- return algos.is_monotonic_int64(values)
535
+ return algos.is_monotonic_int64(values, timelike = True )
525
536
526
537
cpdef get_loc(self , object val):
527
538
if is_definitely_invalid_key(val):
528
539
raise TypeError
529
540
530
541
# Welcome to the spaghetti factory
531
542
532
- if self .over_size_threshold and self .is_monotonic :
543
+ if self .over_size_threshold and self .is_monotonic_increasing :
533
544
if not self .is_unique:
534
545
val = _to_i8(val)
535
546
return self ._get_loc_duplicates(val)
0 commit comments