Skip to content

Commit a1c6a22

Browse files
authored
PERF: assert_index_equal with MultiIndex (#51544)
1 parent 3f3102b commit a1c6a22

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

pandas/_testing/asserters.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ def _get_ilevel_values(index, level):
279279
right = safe_sort_index(right)
280280

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

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

305304
# skip exact index checking when `check_categorical` is False
306-
if check_exact and check_categorical:
305+
elif check_exact and check_categorical:
307306
if not left.equals(right):
308307
mismatch = left._values != right._values
309308

pandas/tests/indexes/multi/test_setops.py

+2
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ def test_union_with_missing_values_on_both_sides(nulls_fixture):
558558
mi2 = MultiIndex.from_arrays([[1, nulls_fixture, 3]])
559559
result = mi1.union(mi2)
560560
expected = MultiIndex.from_arrays([[1, 3, nulls_fixture]])
561+
# We don't particularly care about having levels[0] be float64, but it is
562+
expected = expected.set_levels([expected.levels[0].astype(np.float64)])
561563
tm.assert_index_equal(result, expected)
562564

563565

0 commit comments

Comments
 (0)