Skip to content

Commit 17a4cac

Browse files
authored
Address violation fix (#56328)
1 parent 0d8e0a4 commit 17a4cac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pandas/core/methods/selectn.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def compute(self, method: str) -> Series:
140140
# arr passed into kth_smallest must be contiguous. We copy
141141
# here because kth_smallest will modify its input
142142
# avoid OOB access with kth_smallest_c when n <= 0
143-
kth_val = libalgos.kth_smallest(arr.copy(order="C"), max(n - 1, 0))
143+
if len(arr) > 0:
144+
kth_val = libalgos.kth_smallest(arr.copy(order="C"), n - 1)
145+
else:
146+
kth_val = np.nan
144147
(ns,) = np.nonzero(arr <= kth_val)
145148
inds = ns[arr[ns].argsort(kind="mergesort")]
146149

0 commit comments

Comments
 (0)