-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
MultiIndex.is_monotonic_increasing #32179
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
Comments
The DOC could be improved and better clarified |
Thanks for the reply. MultiIndex also has the attribute |
Given the bug you uncovered in #32259, at the moment I'd say it's more accurate :) |
Sorry, I think I was wrong. By looking at the docs, it says
Notice how it explicitly says codes rather than values. So, I think #32259 is actually fine as it is (not a bug), because there the values are sorted. This clarifies the difference here - is_monotonic_increasing/decreasing check that the values are increasing / decreasing, while is_lexsorted just checks the codes.
Yes, IMO a note to clarify this difference would be good |
Does that mean MultiIndex.sortlevel will also only be sorting the codes, rather than values? This would be rather confusing and will not be useful for users ... I am wondering in what cases codes have different order from values? sortlevel is critical to a software I am writing (alternatives like MultiIndex.sort_values() are extremely slow for my cases). |
By looking at the source code, that seems to be the case.
If I've understood Might want to keep an eye on the thread in #32312 |
I guess potentially in MultiIndex.sortlevel, it can check the MultiIndex.levels[i].is_monotonic_increasing on each of its level, and resort those MultiIndex.levels[i] that are not sorted (as well as resetting its corresponding codes). |
Would resetting the index ( |
Thanks. That would be a bit slow for our usage (our typical usage has 4 ~ 5 levels and 10m ~ 100m rows). What I end up doing now is to always check that all MultiIndex.levels[i].is_monotonic_increasing is True before doing sortlevel. It seems that unless the MultiIndex is intentionally set with unsorted levels (like what happens with groupby with sort=False), in all other cases the levels are indeed sorted. |
This does not seem to be documented anywhere. For MultiIndex, how is
.is_monotonic_increasing
different from.is_lexsorted
?The text was updated successfully, but these errors were encountered: