From 8e3eaf78b571a5c8418caf048ceca0a5a48add28 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 16 Jul 2021 14:38:57 -0700 Subject: [PATCH] Revert "PERF: tighten _should_compare for MultiIndex (#42231)" This reverts commit 381dd06d6d901ebc77df5908a0b3461dae244236. --- pandas/core/indexes/base.py | 18 ------------------ pandas/tests/indexes/multi/test_indexing.py | 9 --------- 2 files changed, 27 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 5866644860831..13d1caedbb50a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5514,16 +5514,6 @@ def _get_indexer_non_comparable( """ if method is not None: other = unpack_nested_dtype(target) - if self._is_multi ^ other._is_multi: - kind = other.dtype.type if self._is_multi else self.dtype.type - raise TypeError( - f"'<' not supported between instances of {kind} and 'tuple'" - ) - elif self._is_multi and other._is_multi: - assert self.nlevels != other.nlevels - # Python allows comparison between tuples of different lengths, - # but for our purposes such a comparison is not meaningful. - raise TypeError("'<' not supported between tuples of different lengths") raise TypeError(f"Cannot compare dtypes {self.dtype} and {other.dtype}") no_matches = -1 * np.ones(target.shape, dtype=np.intp) @@ -5653,14 +5643,6 @@ def _should_compare(self, other: Index) -> bool: other = unpack_nested_dtype(other) dtype = other.dtype - if other._is_multi: - if not self._is_multi: - # other contains only tuples so unless we are object-dtype, - # there can never be any matches - return self._is_comparable_dtype(dtype) - return self.nlevels == other.nlevels - # TODO: we can get more specific requiring levels are comparable? - return self._is_comparable_dtype(dtype) or is_object_dtype(dtype) def _is_comparable_dtype(self, dtype: DtypeObj) -> bool: diff --git a/pandas/tests/indexes/multi/test_indexing.py b/pandas/tests/indexes/multi/test_indexing.py index ec7ddf8b4d67a..9e1097ce5951f 100644 --- a/pandas/tests/indexes/multi/test_indexing.py +++ b/pandas/tests/indexes/multi/test_indexing.py @@ -457,15 +457,6 @@ def test_get_indexer_kwarg_validation(self): with pytest.raises(ValueError, match=msg): mi.get_indexer(mi[:-1], tolerance="piano") - def test_get_indexer_mismatched_nlevels(self): - mi = MultiIndex.from_product([range(3), ["A", "B"]]) - - other = MultiIndex.from_product([range(3), ["A", "B"], range(2)]) - - msg = "tuples of different lengths" - with pytest.raises(TypeError, match=msg): - mi.get_indexer(other, method="pad") - def test_getitem(idx): # scalar