Skip to content

Commit 8e3eaf7

Browse files
authored
Revert "PERF: tighten _should_compare for MultiIndex (#42231)"
This reverts commit 381dd06.
1 parent 318bed9 commit 8e3eaf7

File tree

2 files changed

+0
-27
lines changed

2 files changed

+0
-27
lines changed

pandas/core/indexes/base.py

-18
Original file line numberDiff line numberDiff line change
@@ -5514,16 +5514,6 @@ def _get_indexer_non_comparable(
55145514
"""
55155515
if method is not None:
55165516
other = unpack_nested_dtype(target)
5517-
if self._is_multi ^ other._is_multi:
5518-
kind = other.dtype.type if self._is_multi else self.dtype.type
5519-
raise TypeError(
5520-
f"'<' not supported between instances of {kind} and 'tuple'"
5521-
)
5522-
elif self._is_multi and other._is_multi:
5523-
assert self.nlevels != other.nlevels
5524-
# Python allows comparison between tuples of different lengths,
5525-
# but for our purposes such a comparison is not meaningful.
5526-
raise TypeError("'<' not supported between tuples of different lengths")
55275517
raise TypeError(f"Cannot compare dtypes {self.dtype} and {other.dtype}")
55285518

55295519
no_matches = -1 * np.ones(target.shape, dtype=np.intp)
@@ -5653,14 +5643,6 @@ def _should_compare(self, other: Index) -> bool:
56535643

56545644
other = unpack_nested_dtype(other)
56555645
dtype = other.dtype
5656-
if other._is_multi:
5657-
if not self._is_multi:
5658-
# other contains only tuples so unless we are object-dtype,
5659-
# there can never be any matches
5660-
return self._is_comparable_dtype(dtype)
5661-
return self.nlevels == other.nlevels
5662-
# TODO: we can get more specific requiring levels are comparable?
5663-
56645646
return self._is_comparable_dtype(dtype) or is_object_dtype(dtype)
56655647

56665648
def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:

pandas/tests/indexes/multi/test_indexing.py

-9
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,6 @@ def test_get_indexer_kwarg_validation(self):
457457
with pytest.raises(ValueError, match=msg):
458458
mi.get_indexer(mi[:-1], tolerance="piano")
459459

460-
def test_get_indexer_mismatched_nlevels(self):
461-
mi = MultiIndex.from_product([range(3), ["A", "B"]])
462-
463-
other = MultiIndex.from_product([range(3), ["A", "B"], range(2)])
464-
465-
msg = "tuples of different lengths"
466-
with pytest.raises(TypeError, match=msg):
467-
mi.get_indexer(other, method="pad")
468-
469460

470461
def test_getitem(idx):
471462
# scalar

0 commit comments

Comments
 (0)