Skip to content

Commit

Permalink
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
@@ -930,6 +930,16 @@ def time_frame_xs_row(self):
self.df.xs(50000)


class frame_sort_index(object):
goal_time = 0.2

def setup(self):
self.df = DataFrame(randn(1000000, 2), columns=list('AB'))

def time_frame_sort_index(self):
self.df.sort_index()


class series_string_vector_slice(object):
goal_time = 0.2

2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.17.1.txt
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@ Deprecations
Performance Improvements
~~~~~~~~~~~~~~~~~~~~~~~~

- Checking monotonic-ness before sorting on an index (:issue:`11080`)

.. _whatsnew_0171.bug_fixes:

Bug Fixes
9 changes: 9 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
@@ -3157,6 +3157,15 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
else:
from pandas.core.groupby import _nargsort

# GH11080 - Check monotonic-ness before sort an index
# if monotonic (already sorted), return None or copy() according to 'inplace'
if (ascending and labels.is_monotonic_increasing) or \
(not ascending and labels.is_monotonic_decreasing):
if inplace:
return
else:
return self.copy()

indexer = _nargsort(labels, kind=kind, ascending=ascending,
na_position=na_position)

0 comments on commit b40c1ab

Please sign in to comment.