Skip to content

Commit 9901c8c

Browse files
simonjayhawkinsluckyvs1
authored andcommitted
Revert "REF: remove special casing from Index.equals (always dispatch to subclass) (pandas-dev#35330)" (pandas-dev#38560)
This reverts commit 0b90685.
1 parent 0c14918 commit 9901c8c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pandas/core/indexes/base.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -4442,15 +4442,16 @@ def equals(self, other: object) -> bool:
44424442
if not isinstance(other, Index):
44434443
return False
44444444

4445-
# If other is a subclass of self and defines its own equals method, we
4446-
# dispatch to the subclass method. For instance for a MultiIndex,
4447-
# a d-level MultiIndex can equal d-tuple Index.
4448-
# Note: All EA-backed Index subclasses override equals
4449-
if (
4450-
isinstance(other, type(self))
4451-
and type(other) is not type(self)
4452-
and other.equals is not self.equals
4453-
):
4445+
if is_object_dtype(self.dtype) and not is_object_dtype(other.dtype):
4446+
# if other is not object, use other's logic for coercion
4447+
return other.equals(self)
4448+
4449+
if isinstance(other, ABCMultiIndex):
4450+
# d-level MultiIndex can equal d-tuple Index
4451+
return other.equals(self)
4452+
4453+
if is_extension_array_dtype(other.dtype):
4454+
# All EA-backed Index subclasses override equals
44544455
return other.equals(self)
44554456

44564457
return array_equivalent(self._values, other._values)

0 commit comments

Comments
 (0)