Skip to content

Improve performance of equality comparison between a simple Index and a MultiIndex #29134

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 13 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4333,6 +4333,11 @@ def equals(self, other):
# if other is not object, use other's logic for coercion
return other.equals(self)

if isinstance(other, ABCMultiIndex):
if not is_object_dtype(self): # d-level MultiIndex can equal d-tuple Index
if self.nlevels != other.nlevels:
return False

return array_equivalent(
com.values_from_object(self), com.values_from_object(other)
)
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,10 @@ def equals(self, other):
return False

if not isinstance(other, MultiIndex):
if not is_object_dtype(other): # d-level MultiIndex can equal d-tuple Index
if self.nlevels != other.nlevels:
return False

other_vals = com.values_from_object(ensure_index(other))
return array_equivalent(self._ndarray_values, other_vals)

Expand Down