Skip to content

Commit 0b90685

Browse files
REF: remove special casing from Index.equals (always dispatch to subclass) (#35330)
1 parent b68b604 commit 0b90685

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pandas/core/indexes/base.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -4252,16 +4252,15 @@ def equals(self, other: Any) -> bool:
42524252
if not isinstance(other, Index):
42534253
return False
42544254

4255-
if is_object_dtype(self.dtype) and not is_object_dtype(other.dtype):
4256-
# if other is not object, use other's logic for coercion
4257-
return other.equals(self)
4258-
4259-
if isinstance(other, ABCMultiIndex):
4260-
# d-level MultiIndex can equal d-tuple Index
4261-
return other.equals(self)
4262-
4263-
if is_extension_array_dtype(other.dtype):
4264-
# All EA-backed Index subclasses override equals
4255+
# If other is a subclass of self and defines it's own equals method, we
4256+
# dispatch to the subclass method. For instance for a MultiIndex,
4257+
# a d-level MultiIndex can equal d-tuple Index.
4258+
# Note: All EA-backed Index subclasses override equals
4259+
if (
4260+
isinstance(other, type(self))
4261+
and type(other) is not type(self)
4262+
and other.equals is not self.equals
4263+
):
42654264
return other.equals(self)
42664265

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

0 commit comments

Comments
 (0)