Skip to content

Commit 3054c45

Browse files
simonjayhawkinsmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#38560: Revert "REF: remove special casing from Index.equals (always dispatchto subclass) (pandas-dev#35330)"
1 parent b381e4f commit 3054c45

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
@@ -4455,15 +4455,16 @@ def equals(self, other: object) -> bool:
44554455
if not isinstance(other, Index):
44564456
return False
44574457

4458-
# If other is a subclass of self and defines its own equals method, we
4459-
# dispatch to the subclass method. For instance for a MultiIndex,
4460-
# a d-level MultiIndex can equal d-tuple Index.
4461-
# Note: All EA-backed Index subclasses override equals
4462-
if (
4463-
isinstance(other, type(self))
4464-
and type(other) is not type(self)
4465-
and other.equals is not self.equals
4466-
):
4458+
if is_object_dtype(self.dtype) and not is_object_dtype(other.dtype):
4459+
# if other is not object, use other's logic for coercion
4460+
return other.equals(self)
4461+
4462+
if isinstance(other, ABCMultiIndex):
4463+
# d-level MultiIndex can equal d-tuple Index
4464+
return other.equals(self)
4465+
4466+
if is_extension_array_dtype(other.dtype):
4467+
# All EA-backed Index subclasses override equals
44674468
return other.equals(self)
44684469

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

0 commit comments

Comments
 (0)