Skip to content

PERF: Remove unnecessary copies in sorting functions (#33917) #34192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 3, 2020
10 changes: 10 additions & 0 deletions asv_bench/benchmarks/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,14 @@ def time_argsort(self, N):
self.array.argsort()


class SortIndexSeries:
def setup(self):
N = 10 ** 5
idx = pd.date_range(start="1/1/2000", periods=N, freq="s")
self.s = pd.Series(np.random.randn(N), index=idx)

def time_sort_index(self):
self.s.sort_index()


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this. SortIndex.time_sort_index already covers this code path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I haven't checked timeseries before adding asv

from .pandas_vb_common import setup # noqa: F401 isort:skip
2 changes: 1 addition & 1 deletion pandas/core/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def ensure_key_mapped(values, key: Optional[Callable], levels=None):
from pandas.core.indexes.api import Index

if not key:
return values.copy()
return values

if isinstance(values, ABCMultiIndex):
return ensure_key_mapped_multiindex(values, key, level=levels)
Expand Down