1
1
cimport cython
2
+ from cpython.sequence cimport PySequence_GetItem
2
3
3
4
import numpy as np
4
5
@@ -77,7 +78,7 @@ cdef ndarray _get_bool_indexer(ndarray values, object val, ndarray mask = None):
77
78
indexer = np.empty(len (values), dtype = np.uint8)
78
79
79
80
for i in range (len (values)):
80
- item = values[i]
81
+ item = PySequence_GetItem( values, i)
81
82
indexer[i] = is_matching_na(item, val)
82
83
83
84
else :
@@ -405,7 +406,7 @@ cdef class IndexEngine:
405
406
found_nas = set ()
406
407
407
408
for i in range (n):
408
- val = values[i]
409
+ val = PySequence_GetItem( values, i)
409
410
410
411
# GH#43870
411
412
# handle lookup for nas
@@ -437,7 +438,7 @@ cdef class IndexEngine:
437
438
d[val].append(i)
438
439
439
440
for i in range (n_t):
440
- val = targets[i]
441
+ val = PySequence_GetItem( targets, i)
441
442
442
443
# ensure there are nas in values before looking for a matching na
443
444
if check_na_values and checknull(val):
@@ -488,22 +489,22 @@ cdef Py_ssize_t _bin_search(ndarray values, object val) except -1:
488
489
Py_ssize_t mid = 0 , lo = 0 , hi = len (values) - 1
489
490
object pval
490
491
491
- if hi == 0 or (hi > 0 and val > values[hi] ):
492
+ if hi == 0 or (hi > 0 and val > PySequence_GetItem( values, hi) ):
492
493
return len (values)
493
494
494
495
while lo < hi:
495
496
mid = (lo + hi) // 2
496
- pval = values[ mid]
497
+ pval = PySequence_GetItem( values, mid)
497
498
if val < pval:
498
499
hi = mid
499
500
elif val > pval:
500
501
lo = mid + 1
501
502
else :
502
- while mid > 0 and val == values[ mid - 1 ] :
503
+ while mid > 0 and val == PySequence_GetItem( values, mid - 1 ) :
503
504
mid -= 1
504
505
return mid
505
506
506
- if val <= values[ mid] :
507
+ if val <= PySequence_GetItem( values, mid) :
507
508
return mid
508
509
else :
509
510
return mid + 1
@@ -591,7 +592,7 @@ cdef class DatetimeEngine(Int64Engine):
591
592
592
593
loc = values.searchsorted(conv, side = " left" )
593
594
594
- if loc == len (values) or values[ loc] != conv:
595
+ if loc == len (values) or PySequence_GetItem( values, loc) != conv:
595
596
raise KeyError (val)
596
597
return loc
597
598
@@ -962,7 +963,7 @@ cdef class SharedEngine:
962
963
res = np.empty(N, dtype = np.intp)
963
964
964
965
for i in range(N ):
965
- val = values[i]
966
+ val = PySequence_GetItem( values, i)
966
967
try :
967
968
loc = self .get_loc(val)
968
969
# Because we are unique, loc should always be an integer
@@ -996,7 +997,7 @@ cdef class SharedEngine:
996
997
997
998
# See also IntervalIndex.get_indexer_pointwise
998
999
for i in range (N):
999
- val = targets[i]
1000
+ val = PySequence_GetItem( targets, i)
1000
1001
1001
1002
try :
1002
1003
locs = self .get_loc(val)
@@ -1176,9 +1177,9 @@ cdef class MaskedIndexEngine(IndexEngine):
1176
1177
na_pos = []
1177
1178
1178
1179
for i in range (n):
1179
- val = values[i]
1180
+ val = PySequence_GetItem( values, i)
1180
1181
1181
- if mask[i] :
1182
+ if PySequence_GetItem( mask, i) :
1182
1183
na_pos.append(i)
1183
1184
1184
1185
else :
@@ -1188,9 +1189,9 @@ cdef class MaskedIndexEngine(IndexEngine):
1188
1189
d[val].append(i)
1189
1190
1190
1191
for i in range (n_t):
1191
- val = target_vals[i]
1192
+ val = PySequence_GetItem( target_vals, i)
1192
1193
1193
- if target_mask[i] :
1194
+ if PySequence_GetItem( target_mask, i) :
1194
1195
if na_pos:
1195
1196
for na_idx in na_pos:
1196
1197
# realloc if needed
0 commit comments