Skip to content

API: MultiIndex.names|codes|levels returns tuples #57042

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 13 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix doctest, test
  • Loading branch information
mroeschke committed Jan 25, 2024
commit 8a36d34aad79c9c5387175f57fafbb1b15017859
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ def _set_names(self, names, *, level=None, validate: bool = True) -> None:
>>> mi
MultiIndex([(1, 3, 5),
(2, 4, 6)],
names=['x', 'y', 'z'])
names=('x', 'y', 'z'))
>>> mi.names
('x', 'y', 'z')
""",
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def _all_key(key):
if isinstance(piece.index, MultiIndex):
# We are adding an empty level
transformed_piece.index = MultiIndex.from_tuples(
[all_key], names=piece.index.names + [None]
[all_key], names=piece.index.names + (None,)
)
else:
transformed_piece.index = Index([all_key], name=piece.index.name)
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/reshape/merge/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,10 @@ def test_join_multi_levels2(self):

class TestJoinMultiMulti:
def test_join_multi_multi(self, left_multi, right_multi, join_type, on_cols_multi):
left_names = left_multi.index.names
right_names = right_multi.index.names
if join_type == "right":
level_order = right_names + left_names.difference(right_names)
level_order = ["Origin", "Destination", "Period", "LinkType", "TripPurp"]
else:
level_order = left_names + right_names.difference(left_names)
level_order = ["Origin", "Destination", "Period", "TripPurp", "LinkType"]
# Multi-index join tests
expected = (
merge(
Expand Down