Skip to content

Commit

Permalink
BUG: Multiindex.equals not commutative for ea dtype (pandas-dev#46047)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Feb 26, 2022
1 parent 60c2940 commit 443f2b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/indexes/multi/test_equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 443f2b1

Please sign in to comment.