@@ -5384,6 +5384,16 @@ def _get_indexer_non_comparable(
5384
5384
"""
5385
5385
if method is not None :
5386
5386
other = unpack_nested_dtype (target )
5387
+ if self ._is_multi ^ other ._is_multi :
5388
+ kind = other .dtype .type if self ._is_multi else self .dtype .type
5389
+ raise TypeError (
5390
+ f"'<' not supported between instances of { kind } and 'tuple'"
5391
+ )
5392
+ elif self ._is_multi and other ._is_multi :
5393
+ assert self .nlevels != other .nlevels
5394
+ # Python allows comparison between tuples of different lengths,
5395
+ # but for our purposes such a comparison is not meaningful.
5396
+ raise TypeError ("'<' not supported between tuples of different lengths" )
5387
5397
raise TypeError (f"Cannot compare dtypes { self .dtype } and { other .dtype } " )
5388
5398
5389
5399
no_matches = - 1 * np .ones (target .shape , dtype = np .intp )
@@ -5513,6 +5523,14 @@ def _should_compare(self, other: Index) -> bool:
5513
5523
5514
5524
other = unpack_nested_dtype (other )
5515
5525
dtype = other .dtype
5526
+ if other ._is_multi :
5527
+ if not self ._is_multi :
5528
+ # other contains only tuples so unless we are object-dtype,
5529
+ # there can never be any matches
5530
+ return self ._is_comparable_dtype (dtype )
5531
+ return self .nlevels == other .nlevels
5532
+ # TODO: we can get more specific requiring levels are comparable?
5533
+
5516
5534
return self ._is_comparable_dtype (dtype ) or is_object_dtype (dtype )
5517
5535
5518
5536
def _is_comparable_dtype (self , dtype : DtypeObj ) -> bool :
0 commit comments