Skip to content

Commit 198df89

Browse files
jbrockmendelfeefladder
authored andcommitted
Revert "PERF: tighten _should_compare for MultiIndex (pandas-dev#42231)" (pandas-dev#42575)
This reverts commit 381dd06.
1 parent 705b060 commit 198df89

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
@@ -458,15 +458,6 @@ def test_get_indexer_kwarg_validation(self):
458458
with pytest.raises(ValueError, match=msg):
459459
mi.get_indexer(mi[:-1], tolerance="piano")
460460

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

471462
def test_getitem(idx):
472463
# scalar

0 commit comments

Comments
 (0)