Skip to content

PERF: sort_index with an already monotonic MultiIndex #54883

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 2 commits into from
Aug 31, 2023

Conversation

lukemanley
Copy link
Member

@lukemanley lukemanley commented Aug 30, 2023

import pandas as pd
import numpy as np

mi = pd.MultiIndex.from_product([np.arange(1000)] * 2)
df = pd.DataFrame(np.random.randn(len(mi)), index=mi)

%timeit df.sort_index()

# 100 ms ± 2.22 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)  <- main
# 4.17 ms ± 62.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  <- PR

@lukemanley lukemanley added Performance Memory or execution speed performance MultiIndex labels Aug 30, 2023
@lukemanley lukemanley added this to the 2.2 milestone Aug 30, 2023
@mroeschke mroeschke merged commit eafceae into pandas-dev:main Aug 31, 2023
@mroeschke
Copy link
Member

Thanks @lukemanley

@lukemanley lukemanley deleted the monotonic-mi-sort-index branch September 6, 2023 00:53
mroeschke pushed a commit to mroeschke/pandas that referenced this pull request Sep 11, 2023
* PERF: sort_index with an already monotonic MultiIndex

* whatsnew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MultiIndex Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants