@@ -793,8 +793,7 @@ def _get_setitem_indexer(self, key):
793793 if (
794794 isinstance (ax , MultiIndex )
795795 and self .name != "iloc"
796- and is_hashable (key )
797- and not isinstance (key , slice )
796+ and is_hashable (key , allow_slice = False )
798797 ):
799798 with suppress (KeyError , InvalidIndexError ):
800799 # TypeError e.g. passed a bool
@@ -1147,8 +1146,7 @@ def _contains_slice(x: object) -> bool:
11471146 # This should never be reached, but let's be explicit about it
11481147 raise ValueError ("Too many indices" ) # pragma: no cover
11491148 if all (
1150- (is_hashable (x ) and not _contains_slice (x )) or com .is_null_slice (x )
1151- for x in tup
1149+ is_hashable (x , allow_slice = False ) or com .is_null_slice (x ) for x in tup
11521150 ):
11531151 # GH#10521 Series should reduce MultiIndex dimensions instead of
11541152 # DataFrame, IndexingError is not raised when slice(None,None,None)
@@ -1511,12 +1509,8 @@ def _convert_to_indexer(self, key, axis: AxisInt):
15111509
15121510 # Slices are not valid keys passed in by the user,
15131511 # even though they are hashable in Python 3.12
1514- contains_slice = False
1515- if isinstance (key , tuple ):
1516- contains_slice = any (isinstance (v , slice ) for v in key )
1517-
15181512 if is_scalar (key ) or (
1519- isinstance (labels , MultiIndex ) and is_hashable (key ) and not contains_slice
1513+ isinstance (labels , MultiIndex ) and is_hashable (key , allow_slice = False )
15201514 ):
15211515 # Otherwise get_loc will raise InvalidIndexError
15221516
0 commit comments