We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0d8e0a4 commit 17a4cacCopy full SHA for 17a4cac
pandas/core/methods/selectn.py
@@ -140,7 +140,10 @@ def compute(self, method: str) -> Series:
140
# arr passed into kth_smallest must be contiguous. We copy
141
# here because kth_smallest will modify its input
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))
+ if len(arr) > 0:
144
+ kth_val = libalgos.kth_smallest(arr.copy(order="C"), n - 1)
145
+ else:
146
+ kth_val = np.nan
147
(ns,) = np.nonzero(arr <= kth_val)
148
inds = ns[arr[ns].argsort(kind="mergesort")]
149
0 commit comments