Skip to content
Open
Changes from 2 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
12 changes: 11 additions & 1 deletion pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,17 @@ def _make_selectors(self) -> None:
self.group_index = comp_index
self.mask = mask
if self.sort:
self.compressor = comp_index.searchsorted(np.arange(ngroups))
import sys

# GH 63314: avoid searchsorted bug with py3.14 + numpy < 2.0
numpy_major = int(np.__version__.split(".")[0])
has_searchsorted_bug = sys.version_info >= (3, 14) and numpy_major < 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some existing constants you can use for this:

from pandas.compat.numpy import np_version_gt2
from pandas.compat import PY314


if has_searchsorted_bug:
# use manual approach instead of buggy searchsorted
self.compressor = np.sort(np.unique(comp_index, return_index=True)[1])
else:
self.compressor = comp_index.searchsorted(np.arange(ngroups))
else:
self.compressor = np.sort(np.unique(comp_index, return_index=True)[1])

Expand Down
Loading