@@ -825,7 +825,15 @@ def _getitem_lowerdim(self, tup: tuple):
825
825
ax0 = self .obj ._get_axis (0 )
826
826
# ...but iloc should handle the tuple as simple integer-location
827
827
# instead of checking it as multiindex representation (GH 13797)
828
- if isinstance (ax0 , MultiIndex ) and self .name != "iloc" :
828
+ if (
829
+ isinstance (ax0 , MultiIndex )
830
+ and self .name != "iloc"
831
+ and not any (isinstance (x , slice ) for x in tup )
832
+ ):
833
+ # Note: in all extant test cases, replacing the slice condition with
834
+ # `all(is_hashable(x) or com.is_null_slice(x) for x in tup)`
835
+ # is equivalent.
836
+ # (see the other place where we call _handle_lowerdim_multi_index_axis0)
829
837
with suppress (IndexingError ):
830
838
return self ._handle_lowerdim_multi_index_axis0 (tup )
831
839
@@ -879,7 +887,7 @@ def _getitem_nested_tuple(self, tup: tuple):
879
887
):
880
888
# GH#35349 Raise if tuple in tuple for series
881
889
raise ValueError ("Too many indices" )
882
- if self . ndim == 1 or not any ( isinstance ( x , slice ) for x in tup ):
890
+ if all ( is_hashable ( x ) or com . is_null_slice ( x ) for x in tup ):
883
891
# GH#10521 Series should reduce MultiIndex dimensions instead of
884
892
# DataFrame, IndexingError is not raised when slice(None,None,None)
885
893
# with one row.
@@ -1117,16 +1125,16 @@ def _handle_lowerdim_multi_index_axis0(self, tup: tuple):
1117
1125
try :
1118
1126
# fast path for series or for tup devoid of slices
1119
1127
return self ._get_label (tup , axis = axis )
1120
- except ( TypeError , InvalidIndexError ) :
1128
+ except TypeError as err :
1121
1129
# slices are unhashable
1122
- pass
1130
+ raise IndexingError ("No label returned" ) from err
1131
+
1123
1132
except KeyError as ek :
1124
1133
# raise KeyError if number of indexers match
1125
1134
# else IndexingError will be raised
1126
1135
if self .ndim < len (tup ) <= self .obj .index .nlevels :
1127
1136
raise ek
1128
-
1129
- raise IndexingError ("No label returned" )
1137
+ raise IndexingError ("No label returned" ) from ek
1130
1138
1131
1139
def _getitem_axis (self , key , axis : int ):
1132
1140
key = item_from_zerodim (key )
0 commit comments