@@ -41,11 +41,13 @@ cdef inline bint is_definitely_invalid_key(object val):
4141
4242
4343cpdef get_value_at(ndarray arr, object loc, object tz = None ):
44+ obj = util.get_value_at(arr, loc)
45+
4446 if arr.descr.type_num == NPY_DATETIME:
45- return Timestamp(util.get_value_at(arr, loc) , tz = tz)
47+ return Timestamp(obj , tz = tz)
4648 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
4951
5052
5153# Don't populate hash tables in monotonic indexes larger than this
@@ -102,6 +104,9 @@ cdef class IndexEngine:
102104 arr[loc] = value
103105
104106 cpdef get_loc(self , object val):
107+ cdef:
108+ Py_ssize_t loc
109+
105110 if is_definitely_invalid_key(val):
106111 raise TypeError (" '{val}' is an invalid key" .format(val = val))
107112
@@ -114,7 +119,7 @@ cdef class IndexEngine:
114119 loc = _bin_search(values, val) # .searchsorted(val, side='left')
115120 if loc >= len (values):
116121 raise KeyError (val)
117- if util.get_value_at( values, loc) != val:
122+ if values[ loc] != val:
118123 raise KeyError (val)
119124 return loc
120125
@@ -352,22 +357,22 @@ cdef Py_ssize_t _bin_search(ndarray values, object val) except -1:
352357 Py_ssize_t mid = 0 , lo = 0 , hi = len (values) - 1
353358 object pval
354359
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] ):
356361 return len (values)
357362
358363 while lo < hi:
359364 mid = (lo + hi) // 2
360- pval = util.get_value_at( values, mid)
365+ pval = values[ mid]
361366 if val < pval:
362367 hi = mid
363368 elif val > pval:
364369 lo = mid + 1
365370 else :
366- while mid > 0 and val == util.get_value_at( values, mid - 1 ) :
371+ while mid > 0 and val == values[ mid - 1 ] :
367372 mid -= 1
368373 return mid
369374
370- if val <= util.get_value_at( values, mid) :
375+ if val <= values[ mid] :
371376 return mid
372377 else :
373378 return mid + 1
@@ -387,13 +392,16 @@ cdef class DatetimeEngine(Int64Engine):
387392 return ' M8[ns]'
388393
389394 def __contains__ (self , object val ):
395+ cdef:
396+ int64_t loc
397+
390398 if self .over_size_threshold and self .is_monotonic_increasing:
391399 if not self .is_unique:
392400 return self ._get_loc_duplicates(val)
393401 values = self ._get_index_values()
394402 conv = maybe_datetimelike_to_i8(val)
395403 loc = values.searchsorted(conv, side = ' left' )
396- return util.get_value_at( values, loc) == conv
404+ return values[ loc] == conv
397405
398406 self ._ensure_mapping_populated()
399407 return maybe_datetimelike_to_i8(val) in self .mapping
@@ -405,6 +413,8 @@ cdef class DatetimeEngine(Int64Engine):
405413 return algos.is_monotonic(values, timelike = True )
406414
407415 cpdef get_loc(self , object val):
416+ cdef:
417+ int64_t loc
408418 if is_definitely_invalid_key(val):
409419 raise TypeError
410420
@@ -422,7 +432,7 @@ cdef class DatetimeEngine(Int64Engine):
422432 self ._date_check_type(val)
423433 raise KeyError (val)
424434
425- if loc == len (values) or util.get_value_at( values, loc) != conv:
435+ if loc == len (values) or values[ loc] != conv:
426436 raise KeyError (val)
427437 return loc
428438
0 commit comments