We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ec9be9d commit 97828e4Copy full SHA for 97828e4
pandas/core/methods/selectn.py
@@ -139,7 +139,8 @@ def compute(self, method: str) -> Series:
139
140
# arr passed into kth_smallest must be contiguous. We copy
141
# here because kth_smallest will modify its input
142
- kth_val = libalgos.kth_smallest(arr.copy(order="C"), n - 1)
+ # avoid OOB access with kth_smallest_c when n <= 0
143
+ kth_val = libalgos.kth_smallest(arr.copy(order="C"), max(n - 1, 0))
144
(ns,) = np.nonzero(arr <= kth_val)
145
inds = ns[arr[ns].argsort(kind="mergesort")]
146
0 commit comments