Skip to content

Commit aa50eed

Browse files
committed
Modify nargsort
1 parent b401cba commit aa50eed

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pandas/core/sorting.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,11 @@ def nargsort(items, kind='quicksort', ascending=True, na_position='last'):
247247
mask = isna(items)
248248
cnt_null = mask.sum()
249249
sorted_idx = items.argsort(ascending=ascending, kind=kind)
250-
if ascending and na_position == 'last':
251-
# NaN is coded as -1 and is listed in front after sorting
252-
sorted_idx = np.roll(sorted_idx, -cnt_null)
253-
elif not ascending and na_position == 'first':
254-
# NaN is coded as -1 and is listed in the end after sorting
250+
251+
if ascending and na_position == 'first':
255252
sorted_idx = np.roll(sorted_idx, cnt_null)
253+
elif not ascending and na_position == 'last':
254+
sorted_idx = np.roll(sorted_idx, -cnt_null)
256255
return sorted_idx
257256

258257
with warnings.catch_warnings():

0 commit comments

Comments
 (0)