@@ -82,7 +82,7 @@ cdef class IndexEngine:
82
82
83
83
cdef:
84
84
bint unique, monotonic_inc, monotonic_dec
85
- bint initialized, monotonic_check
85
+ bint initialized, monotonic_check, unique_check
86
86
87
87
def __init__ (self , vgetter , n ):
88
88
self .vgetter = vgetter
@@ -91,6 +91,7 @@ cdef class IndexEngine:
91
91
92
92
self .initialized = 0
93
93
self .monotonic_check = 0
94
+ self .unique_check = 0
94
95
95
96
self .unique = 0
96
97
self .monotonic_inc = 0
@@ -177,8 +178,8 @@ cdef class IndexEngine:
177
178
return left
178
179
else :
179
180
return slice (left, right)
180
- else :
181
- return self ._maybe_get_bool_indexer(val)
181
+
182
+ return self ._maybe_get_bool_indexer(val)
182
183
183
184
cdef _maybe_get_bool_indexer(self , object val):
184
185
cdef:
@@ -215,6 +216,7 @@ cdef class IndexEngine:
215
216
if not self .initialized:
216
217
self .initialize()
217
218
219
+ self .unique_check = 1
218
220
return self .unique == 1
219
221
220
222
property is_monotonic_increasing :
@@ -234,16 +236,24 @@ cdef class IndexEngine:
234
236
return self .monotonic_dec == 1
235
237
236
238
cdef inline _do_monotonic_check(self ):
239
+ cdef object is_unique
237
240
try :
238
241
values = self ._get_index_values()
239
- self .monotonic_inc, self .monotonic_dec = \
242
+ self .monotonic_inc, self .monotonic_dec, is_unique = \
240
243
self ._call_monotonic(values)
241
244
except TypeError :
242
245
self .monotonic_inc = 0
243
246
self .monotonic_dec = 0
247
+ is_unique = 0
244
248
245
249
self .monotonic_check = 1
246
250
251
+ # we can only be sure of uniqueness if is_unique=1
252
+ if is_unique:
253
+ self .initialized = 1
254
+ self .unique = 1
255
+ self .unique_check = 1
256
+
247
257
cdef _get_index_values(self ):
248
258
return self .vgetter()
249
259
@@ -257,6 +267,10 @@ cdef class IndexEngine:
257
267
hash (val)
258
268
259
269
cdef inline _ensure_mapping_populated(self ):
270
+ # need to reset if we have previously
271
+ # set the initialized from monotonic checks
272
+ if self .unique_check:
273
+ self .initialized = 0
260
274
if not self .initialized:
261
275
self .initialize()
262
276
@@ -274,6 +288,12 @@ cdef class IndexEngine:
274
288
def clear_mapping (self ):
275
289
self .mapping = None
276
290
self .initialized = 0
291
+ self .monotonic_check = 0
292
+ self .unique_check = 0
293
+
294
+ self .unique = 0
295
+ self .monotonic_inc = 0
296
+ self .monotonic_dec = 0
277
297
278
298
def get_indexer (self , values ):
279
299
self ._ensure_mapping_populated()
@@ -537,7 +557,6 @@ cdef class DatetimeEngine(Int64Engine):
537
557
raise TypeError
538
558
539
559
# Welcome to the spaghetti factory
540
-
541
560
if self .over_size_threshold and self .is_monotonic_increasing:
542
561
if not self .is_unique:
543
562
val = _to_i8(val)
0 commit comments