Conversation
PandasMultiIndex.stack passed sortorder=0 to pandas, i.e. that the codes are lexsorted by none of the levels. Pandas trusts it instead of computing the lexsort depth, so selecting a slice of tuples from a stacked dimension raised an UnsortedIndexError. Don't pass sortorder, so that pandas computes it when needed. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dcherian
approved these changes
Oct 8, 2026
6 tasks done
Collaborator
Author
|
I enabled the benchmark just to be sure. But basically what I expect to happen is that instead of pandas verifying the sortorder during |
Contributor
🚀 Some benchmarks got better. To infinity and beyond!
🚀 better · 🐌 worse · 💥 now failing · 🩹 fixed · 🤷 not comparable Comparing |
dcherian
enabled auto-merge (squash)
October 8, 2026 21:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PandasMultiIndex.stackpassedsortorder=0to pandas, which claims that the index is not lexsorted at all. Pandas trusts it, so slicing a stacked dimension with tuples failed:sortorder, so that pandas computes the lexsort depth when neededsortordereagerly when stacking, which copied all codes to int64Why it was
0:sortorder=0was added in #985 (fixing #980) to a helper that built the codes withnp.meshgrid, without an explanation in the code or the PR. #5692 moved it intoPandasMultiIndex.stackand #9522 copied it to the newfrom_productbranch. In pandas,sortorderis the lexsort depth, the number of leading levels the codes are sorted by, so0means "not sorted" rather than e.g. "sorted from level 0". Stacked codes are always fully lexsorted, also for decreasing coordinates (unsorted levels, the case from #980), and pandas slices those correctly by their codes, which the new test checks.Follow-up of #11688 (comment).
Checklist
whats-new.rstAI Disclosure
Tools: Claude Code
[This is Claude Code on behalf of Michael Niklas]
🤖 Generated with Claude Code