Skip to content

REF: remove special casing from Index.equals (always dispatch to subclass) #35330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 3, 2020
15 changes: 5 additions & 10 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4249,16 +4249,11 @@ def equals(self, other: Any) -> bool:
if not isinstance(other, Index):
return False

if is_object_dtype(self.dtype) and not is_object_dtype(other.dtype):
# if other is not object, use other's logic for coercion
return other.equals(self)

if isinstance(other, ABCMultiIndex):
# d-level MultiIndex can equal d-tuple Index
return other.equals(self)

if is_extension_array_dtype(other.dtype):
# All EA-backed Index subclasses override equals
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment about which cases go through here

if (
isinstance(other, type(self))
and type(other) is not type(self)
and other.equals is not self.equals
):
return other.equals(self)

return array_equivalent(self._values, other._values)
Expand Down