Skip to content

Fix Cython 3.0 regression with time_loc_dups #55915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cimport cython
from cpython.sequence cimport PySequence_GetItem

import numpy as np

Expand Down Expand Up @@ -77,7 +78,7 @@ cdef ndarray _get_bool_indexer(ndarray values, object val, ndarray mask = None):
indexer = np.empty(len(values), dtype=np.uint8)

for i in range(len(values)):
item = values[i]
item = PySequence_GetItem(values, i)
indexer[i] = is_matching_na(item, val)

else:
Expand Down Expand Up @@ -405,7 +406,7 @@ cdef class IndexEngine:
found_nas = set()

for i in range(n):
val = values[i]
val = PySequence_GetItem(values, i)

# GH#43870
# handle lookup for nas
Expand Down Expand Up @@ -437,7 +438,7 @@ cdef class IndexEngine:
d[val].append(i)

for i in range(n_t):
val = targets[i]
val = PySequence_GetItem(targets, i)

# ensure there are nas in values before looking for a matching na
if check_na_values and checknull(val):
Expand Down Expand Up @@ -488,22 +489,22 @@ cdef Py_ssize_t _bin_search(ndarray values, object val) except -1:
Py_ssize_t mid = 0, lo = 0, hi = len(values) - 1
object pval

if hi == 0 or (hi > 0 and val > values[hi]):
if hi == 0 or (hi > 0 and val > PySequence_GetItem(values, hi)):
return len(values)

while lo < hi:
mid = (lo + hi) // 2
pval = values[mid]
pval = PySequence_GetItem(values, mid)
if val < pval:
hi = mid
elif val > pval:
lo = mid + 1
else:
while mid > 0 and val == values[mid - 1]:
while mid > 0 and val == PySequence_GetItem(values, mid - 1):
mid -= 1
return mid

if val <= values[mid]:
if val <= PySequence_GetItem(values, mid):
return mid
else:
return mid + 1
Expand Down Expand Up @@ -591,7 +592,7 @@ cdef class DatetimeEngine(Int64Engine):

loc = values.searchsorted(conv, side="left")

if loc == len(values) or values[loc] != conv:
if loc == len(values) or PySequence_GetItem(values, loc) != conv:
raise KeyError(val)
return loc

Expand Down Expand Up @@ -962,7 +963,7 @@ cdef class SharedEngine:
res = np.empty(N, dtype=np.intp)

for i in range(N):
val = values[i]
val = PySequence_GetItem(values, i)
try:
loc = self.get_loc(val)
# Because we are unique, loc should always be an integer
Expand Down Expand Up @@ -996,7 +997,7 @@ cdef class SharedEngine:

# See also IntervalIndex.get_indexer_pointwise
for i in range(N):
val = targets[i]
val = PySequence_GetItem(targets, i)

try:
locs = self.get_loc(val)
Expand Down Expand Up @@ -1176,9 +1177,9 @@ cdef class MaskedIndexEngine(IndexEngine):
na_pos = []

for i in range(n):
val = values[i]
val = PySequence_GetItem(values, i)

if mask[i]:
if PySequence_GetItem(mask, i):
na_pos.append(i)

else:
Expand All @@ -1188,9 +1189,9 @@ cdef class MaskedIndexEngine(IndexEngine):
d[val].append(i)

for i in range(n_t):
val = target_vals[i]
val = PySequence_GetItem(target_vals, i)

if target_mask[i]:
if PySequence_GetItem(target_mask, i):
if na_pos:
for na_idx in na_pos:
# realloc if needed
Expand Down