Skip to content

CLN: avoid values_from_object in Index.equals #32505

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 3 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 7 additions & 8 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4104,7 +4104,6 @@ def __getitem__(self, key):
if com.is_bool_indexer(key):
key = np.asarray(key, dtype=bool)

key = com.values_from_object(key)
result = getitem(key)
if not is_scalar(result):
if np.ndim(result) > 1:
Expand Down Expand Up @@ -4229,19 +4228,19 @@ def equals(self, other) -> bool:
if not isinstance(other, Index):
return False

if is_object_dtype(self) and not is_object_dtype(other):
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
if not is_object_dtype(self.dtype):
if self.nlevels != other.nlevels:
return False
return other.equals(self)

return array_equivalent(
com.values_from_object(self), com.values_from_object(other)
)
if is_extension_array_dtype(other.dtype):
# All EA-backed Index subclasses override equals
return other.equals(self)

return array_equivalent(self._values, other._values)

def identical(self, other) -> bool:
"""
Expand Down
7 changes: 3 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3141,11 +3141,10 @@ def equals(self, other) -> bool:
if not isinstance(other, MultiIndex):
# d-level MultiIndex can equal d-tuple Index
if not is_object_dtype(other.dtype):
if self.nlevels != other.nlevels:
return False
# other cannot contain tuples, so cannot match self
return False

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

if self.nlevels != other.nlevels:
return False
Expand Down