Skip to content

Commit 5e92681

Browse files
committed
fix pivot_table duplicates on py3.14 with old numpy
found the real issue - searchsorted is broken with python 3.14 + numpy 1.26. it's not compress_group_index, it's the compressor calculation in unstack that uses searchsorted. just fallback to the unique/return_index approach for this combo, same as what the non-sorted path does. works with 100k rows now.
1 parent 944c527 commit 5e92681

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/core/reshape/reshape.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,16 @@ def _make_selectors(self) -> None:
234234
self.group_index = comp_index
235235
self.mask = mask
236236
if self.sort:
237-
self.compressor = comp_index.searchsorted(np.arange(ngroups))
237+
import sys
238+
# GH 63314: avoid searchsorted bug with py3.14 + numpy < 2.0
239+
numpy_major = int(np.__version__.split('.')[0])
240+
has_searchsorted_bug = sys.version_info >= (3, 14) and numpy_major < 2
241+
242+
if has_searchsorted_bug:
243+
# use manual approach instead of buggy searchsorted
244+
self.compressor = np.sort(np.unique(comp_index, return_index=True)[1])
245+
else:
246+
self.compressor = comp_index.searchsorted(np.arange(ngroups))
238247
else:
239248
self.compressor = np.sort(np.unique(comp_index, return_index=True)[1])
240249

0 commit comments

Comments
 (0)