Skip to content

Commit 97828e4

Browse files
authored
Fix apply na overflow (#56000)
* fix groupby and apply UB * fix/skip parser overflow * revert unneeded * feedback
1 parent ec9be9d commit 97828e4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pandas/core/methods/selectn.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def compute(self, method: str) -> Series:
139139

140140
# arr passed into kth_smallest must be contiguous. We copy
141141
# here because kth_smallest will modify its input
142-
kth_val = libalgos.kth_smallest(arr.copy(order="C"), n - 1)
142+
# avoid OOB access with kth_smallest_c when n <= 0
143+
kth_val = libalgos.kth_smallest(arr.copy(order="C"), max(n - 1, 0))
143144
(ns,) = np.nonzero(arr <= kth_val)
144145
inds = ns[arr[ns].argsort(kind="mergesort")]
145146

0 commit comments

Comments
 (0)