Skip to content

PERF: assert_index_equal with MultiIndex #51544

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
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ def _get_ilevel_values(index, level):
right = safe_sort_index(right)

# MultiIndex special comparison for little-friendly error messages
if left.nlevels > 1:
left = cast(MultiIndex, left)
if isinstance(left, MultiIndex):
right = cast(MultiIndex, right)

for level in range(left.nlevels):
Expand All @@ -303,7 +302,7 @@ def _get_ilevel_values(index, level):
_check_types(left.levels[level], right.levels[level], obj=obj)

# skip exact index checking when `check_categorical` is False
if check_exact and check_categorical:
elif check_exact and check_categorical:
if not left.equals(right):
mismatch = left._values != right._values

Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/indexes/multi/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ def test_union_with_missing_values_on_both_sides(nulls_fixture):
mi2 = MultiIndex.from_arrays([[1, nulls_fixture, 3]])
result = mi1.union(mi2)
expected = MultiIndex.from_arrays([[1, 3, nulls_fixture]])
# We don't particularly care about having levels[0] be float64, but it is
expected = expected.set_levels([expected.levels[0].astype(np.float64)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug in union, more specifically midx.append

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. i think i looked it at that for unrelated reasons a while back and didn't get anywhere.

tm.assert_index_equal(result, expected)


Expand Down