Skip to content

Commit c294d9d

Browse files
BUG Series.sort_index does not accept parameters kind and na_position
1 parent f0d89e6 commit c294d9d

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

pandas/core/frame.py

-10
Original file line numberDiff line numberDiff line change
@@ -3323,16 +3323,6 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
33233323
else:
33243324
from pandas.core.groupby import _nargsort
33253325

3326-
# GH11080 - Check monotonic-ness before sort an index
3327-
# if monotonic (already sorted), return None or copy() according
3328-
# to 'inplace'
3329-
if ((ascending and labels.is_monotonic_increasing) or
3330-
(not ascending and labels.is_monotonic_decreasing)):
3331-
if inplace:
3332-
return
3333-
else:
3334-
return self.copy()
3335-
33363326
indexer = _nargsort(labels, kind=kind, ascending=ascending,
33373327
na_position=na_position)
33383328

pandas/core/groupby.py

+5
Original file line numberDiff line numberDiff line change
@@ -4280,6 +4280,11 @@ def _nargsort(items, kind='quicksort', ascending=True, na_position='last'):
42804280
if is_categorical_dtype(items):
42814281
return items.argsort(ascending=ascending)
42824282

4283+
# # GH11080 - Check monotonic-ness before sort an index
4284+
if ((ascending and all(x <= y for x, y in zip(items, items[1:]))) or
4285+
(not ascending and all(x >= y for x, y in zip(items, items[1:])))):
4286+
return np.arange(len(items))
4287+
42834288
items = np.asanyarray(items)
42844289
idx = np.arange(len(items))
42854290
mask = isnull(items)

pandas/core/series.py

-7
Original file line numberDiff line numberDiff line change
@@ -1788,13 +1788,6 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
17881788
else:
17891789
from pandas.core.groupby import _nargsort
17901790

1791-
if ((ascending and index.is_monotonic_increasing) or
1792-
(not ascending and index.is_monotonic_decreasing)):
1793-
if inplace:
1794-
return
1795-
else:
1796-
return self.copy()
1797-
17981791
indexer = _nargsort(index, kind=kind, ascending=ascending,
17991792
na_position=na_position)
18001793
new_index = index.take(indexer)

0 commit comments

Comments
 (0)