@@ -41,11 +41,13 @@ cdef inline bint is_definitely_invalid_key(object val):
41
41
42
42
43
43
cpdef get_value_at(ndarray arr, object loc, object tz = None ):
44
+ obj = util.get_value_at(arr, loc)
45
+
44
46
if arr.descr.type_num == NPY_DATETIME:
45
- return Timestamp(util.get_value_at(arr, loc) , tz = tz)
47
+ return Timestamp(obj , tz = tz)
46
48
elif arr.descr.type_num == NPY_TIMEDELTA:
47
- return Timedelta(util.get_value_at(arr, loc) )
48
- return util.get_value_at(arr, loc)
49
+ return Timedelta(obj )
50
+ return obj
49
51
50
52
51
53
# Don't populate hash tables in monotonic indexes larger than this
@@ -102,6 +104,9 @@ cdef class IndexEngine:
102
104
arr[loc] = value
103
105
104
106
cpdef get_loc(self , object val):
107
+ cdef:
108
+ Py_ssize_t loc
109
+
105
110
if is_definitely_invalid_key(val):
106
111
raise TypeError (" '{val}' is an invalid key" .format(val = val))
107
112
@@ -114,7 +119,7 @@ cdef class IndexEngine:
114
119
loc = _bin_search(values, val) # .searchsorted(val, side='left')
115
120
if loc >= len (values):
116
121
raise KeyError (val)
117
- if util.get_value_at( values, loc) != val:
122
+ if values[ loc] != val:
118
123
raise KeyError (val)
119
124
return loc
120
125
@@ -352,22 +357,22 @@ cdef Py_ssize_t _bin_search(ndarray values, object val) except -1:
352
357
Py_ssize_t mid = 0 , lo = 0 , hi = len (values) - 1
353
358
object pval
354
359
355
- if hi == 0 or (hi > 0 and val > util.get_value_at( values, hi) ):
360
+ if hi == 0 or (hi > 0 and val > values[hi] ):
356
361
return len (values)
357
362
358
363
while lo < hi:
359
364
mid = (lo + hi) // 2
360
- pval = util.get_value_at( values, mid)
365
+ pval = values[ mid]
361
366
if val < pval:
362
367
hi = mid
363
368
elif val > pval:
364
369
lo = mid + 1
365
370
else :
366
- while mid > 0 and val == util.get_value_at( values, mid - 1 ) :
371
+ while mid > 0 and val == values[ mid - 1 ] :
367
372
mid -= 1
368
373
return mid
369
374
370
- if val <= util.get_value_at( values, mid) :
375
+ if val <= values[ mid] :
371
376
return mid
372
377
else :
373
378
return mid + 1
@@ -387,13 +392,16 @@ cdef class DatetimeEngine(Int64Engine):
387
392
return ' M8[ns]'
388
393
389
394
def __contains__ (self , object val ):
395
+ cdef:
396
+ int64_t loc
397
+
390
398
if self .over_size_threshold and self .is_monotonic_increasing:
391
399
if not self .is_unique:
392
400
return self ._get_loc_duplicates(val)
393
401
values = self ._get_index_values()
394
402
conv = maybe_datetimelike_to_i8(val)
395
403
loc = values.searchsorted(conv, side = ' left' )
396
- return util.get_value_at( values, loc) == conv
404
+ return values[ loc] == conv
397
405
398
406
self ._ensure_mapping_populated()
399
407
return maybe_datetimelike_to_i8(val) in self .mapping
@@ -405,6 +413,8 @@ cdef class DatetimeEngine(Int64Engine):
405
413
return algos.is_monotonic(values, timelike = True )
406
414
407
415
cpdef get_loc(self , object val):
416
+ cdef:
417
+ int64_t loc
408
418
if is_definitely_invalid_key(val):
409
419
raise TypeError
410
420
@@ -422,7 +432,7 @@ cdef class DatetimeEngine(Int64Engine):
422
432
self ._date_check_type(val)
423
433
raise KeyError (val)
424
434
425
- if loc == len (values) or util.get_value_at( values, loc) != conv:
435
+ if loc == len (values) or values[ loc] != conv:
426
436
raise KeyError (val)
427
437
return loc
428
438
0 commit comments