diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 1c17ba0620ed0..855c4dfe257dd 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -350,7 +350,7 @@ Missing MultiIndex ^^^^^^^^^^ -- +- Bug in :class:`MultiIndex.equals` not commutative when only one side has extension array dtype (:issue:`46026`) - I/O diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index cc6c92a27e344..662f4d252e8cc 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -3611,6 +3611,10 @@ def equals(self, other: object) -> bool: # i.e. ExtensionArray if not self_values.equals(other_values): return False + elif not isinstance(other_values, np.ndarray): + # i.e. other is ExtensionArray + if not other_values.equals(self_values): + return False else: if not array_equivalent(self_values, other_values): return False diff --git a/pandas/tests/indexes/multi/test_equivalence.py b/pandas/tests/indexes/multi/test_equivalence.py index 3854aca9430a8..c6567b86f0da2 100644 --- a/pandas/tests/indexes/multi/test_equivalence.py +++ b/pandas/tests/indexes/multi/test_equivalence.py @@ -288,3 +288,11 @@ def test_multiindex_compare(): expected = Series([False, False]) result = Series(midx > midx) tm.assert_series_equal(result, expected) + + +def test_equals_ea_int_regular_int(): + # GH#46026 + mi1 = MultiIndex.from_arrays([Index([1, 2], dtype="Int64"), [3, 4]]) + mi2 = MultiIndex.from_arrays([[1, 2], [3, 4]]) + assert not mi1.equals(mi2) + assert not mi2.equals(mi1)