Skip to content

Commit 443f2b1

Browse files
authored
BUG: Multiindex.equals not commutative for ea dtype (#46047)
1 parent 60c2940 commit 443f2b1

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/whatsnew/v1.5.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ Missing
350350

351351
MultiIndex
352352
^^^^^^^^^^
353-
-
353+
- Bug in :class:`MultiIndex.equals` not commutative when only one side has extension array dtype (:issue:`46026`)
354354
-
355355

356356
I/O

pandas/core/indexes/multi.py

+4
Original file line numberDiff line numberDiff line change
@@ -3611,6 +3611,10 @@ def equals(self, other: object) -> bool:
36113611
# i.e. ExtensionArray
36123612
if not self_values.equals(other_values):
36133613
return False
3614+
elif not isinstance(other_values, np.ndarray):
3615+
# i.e. other is ExtensionArray
3616+
if not other_values.equals(self_values):
3617+
return False
36143618
else:
36153619
if not array_equivalent(self_values, other_values):
36163620
return False

pandas/tests/indexes/multi/test_equivalence.py

+8
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,11 @@ def test_multiindex_compare():
288288
expected = Series([False, False])
289289
result = Series(midx > midx)
290290
tm.assert_series_equal(result, expected)
291+
292+
293+
def test_equals_ea_int_regular_int():
294+
# GH#46026
295+
mi1 = MultiIndex.from_arrays([Index([1, 2], dtype="Int64"), [3, 4]])
296+
mi2 = MultiIndex.from_arrays([[1, 2], [3, 4]])
297+
assert not mi1.equals(mi2)
298+
assert not mi2.equals(mi1)

0 commit comments

Comments
 (0)