Skip to content

Commit df45c33

Browse files
jbrockmendelSeeminSyed
authored andcommitted
CLN: avoid values_from_object in Index.equals (pandas-dev#32505)
1 parent 4496be2 commit df45c33

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

pandas/core/indexes/base.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -4120,7 +4120,6 @@ def __getitem__(self, key):
41204120
if com.is_bool_indexer(key):
41214121
key = np.asarray(key, dtype=bool)
41224122

4123-
key = com.values_from_object(key)
41244123
result = getitem(key)
41254124
if not is_scalar(result):
41264125
if np.ndim(result) > 1:
@@ -4245,19 +4244,19 @@ def equals(self, other) -> bool:
42454244
if not isinstance(other, Index):
42464245
return False
42474246

4248-
if is_object_dtype(self) and not is_object_dtype(other):
4247+
if is_object_dtype(self.dtype) and not is_object_dtype(other.dtype):
42494248
# if other is not object, use other's logic for coercion
42504249
return other.equals(self)
42514250

42524251
if isinstance(other, ABCMultiIndex):
42534252
# d-level MultiIndex can equal d-tuple Index
4254-
if not is_object_dtype(self.dtype):
4255-
if self.nlevels != other.nlevels:
4256-
return False
4253+
return other.equals(self)
42574254

4258-
return array_equivalent(
4259-
com.values_from_object(self), com.values_from_object(other)
4260-
)
4255+
if is_extension_array_dtype(other.dtype):
4256+
# All EA-backed Index subclasses override equals
4257+
return other.equals(self)
4258+
4259+
return array_equivalent(self._values, other._values)
42614260

42624261
def identical(self, other) -> bool:
42634262
"""

pandas/core/indexes/multi.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -3141,11 +3141,10 @@ def equals(self, other) -> bool:
31413141
if not isinstance(other, MultiIndex):
31423142
# d-level MultiIndex can equal d-tuple Index
31433143
if not is_object_dtype(other.dtype):
3144-
if self.nlevels != other.nlevels:
3145-
return False
3144+
# other cannot contain tuples, so cannot match self
3145+
return False
31463146

3147-
other_vals = com.values_from_object(other)
3148-
return array_equivalent(self._values, other_vals)
3147+
return array_equivalent(self._values, other._values)
31493148

31503149
if self.nlevels != other.nlevels:
31513150
return False

0 commit comments

Comments
 (0)