Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the integer-named MultiIndex conversion fix.
No open issues 🎉
What changed in this PR
Fixes incorrect index data in PyArrow’s pandas conversion when integer MultiIndex level names are mistaken for positional lookups.
Changes:
- Makes MultiIndex level extraction positional while retaining each level’s original name.
- Adds regression coverage for distinct level values, stringified field names, expected warnings, and pandas round-tripping.
| File | Description |
|---|---|
python/pyarrow/tests/test_pandas.py |
Adds a regression test for integer-named MultiIndex levels. |
python/pyarrow/pandas_compat.py |
Uses temporary positional names to avoid ambiguous level lookups. |
Review effort: Balanced
|
|
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.
Rationale for this change
pa.Table.from_pandas()on a DataFrame whoseMultiIndexhas integer level names returned the wrong data for some index levels. For example, withnames=[1, 2]both index columns were named"1"and both contained the values of the first level, so the second level's data was lost.What changes are included in this PR?
_get_index_level_values()inpandas_compat.pycalledindex.get_level_values(i)with a position, but pandas matches an integer against level names before treating it as a position. The levels are now looked up by position regardless of their names.Are these changes tested?
Yes
Are there any user-facing changes?
No
Was AI used for this PR?
Used Claude, asked lots of questions about why etc, did an adversarial review with roborev too
PR code and description written by:
Reviewed before submission by: