@@ -577,18 +577,6 @@ def __call__(self, axis=None):
577577 new_self .axis = axis
578578 return new_self
579579
580- def _get_label (self , label , axis : int ):
581- if self .ndim == 1 :
582- # for perf reasons we want to try _xs first
583- # as its basically direct indexing
584- # but will fail when the index is not present
585- # see GH5667
586- return self .obj ._xs (label , axis = axis )
587- elif isinstance (label , tuple ) and isinstance (label [axis ], slice ):
588- raise IndexingError ("no slices here, handle elsewhere" )
589-
590- return self .obj ._xs (label , axis = axis )
591-
592580 def _get_setitem_indexer (self , key ):
593581 """
594582 Convert a potentially-label-based key into a positional indexer.
@@ -700,23 +688,6 @@ def _convert_tuple(self, key, is_setter: bool = False):
700688 keyidx .append (idx )
701689 return tuple (keyidx )
702690
703- def _handle_lowerdim_multi_index_axis0 (self , tup : Tuple ):
704- # we have an axis0 multi-index, handle or raise
705- axis = self .axis or 0
706- try :
707- # fast path for series or for tup devoid of slices
708- return self ._get_label (tup , axis = axis )
709- except TypeError :
710- # slices are unhashable
711- pass
712- except KeyError as ek :
713- # raise KeyError if number of indexers match
714- # else IndexingError will be raised
715- if len (tup ) <= self .obj .index .nlevels and len (tup ) > self .ndim :
716- raise ek
717-
718- return None
719-
720691 def _getitem_tuple_same_dim (self , tup : Tuple ):
721692 """
722693 Index with indexers that should return an object of the same dimension
@@ -798,6 +769,9 @@ def _getitem_nested_tuple(self, tup: Tuple):
798769 # multi-index dimension, try to see if we have something like
799770 # a tuple passed to a series with a multi-index
800771 if len (tup ) > self .ndim :
772+ if self .name != "loc" :
773+ # This should never be reached, but lets be explicit about it
774+ raise ValueError ("Too many indices" )
801775 result = self ._handle_lowerdim_multi_index_axis0 (tup )
802776 if result is not None :
803777 return result
@@ -1069,6 +1043,35 @@ def _getitem_tuple(self, tup: Tuple):
10691043
10701044 return self ._getitem_tuple_same_dim (tup )
10711045
1046+ def _get_label (self , label , axis : int ):
1047+ if self .ndim == 1 :
1048+ # for perf reasons we want to try _xs first
1049+ # as its basically direct indexing
1050+ # but will fail when the index is not present
1051+ # see GH5667
1052+ return self .obj ._xs (label , axis = axis )
1053+ elif isinstance (label , tuple ) and isinstance (label [axis ], slice ):
1054+ raise IndexingError ("no slices here, handle elsewhere" )
1055+
1056+ return self .obj ._xs (label , axis = axis )
1057+
1058+ def _handle_lowerdim_multi_index_axis0 (self , tup : Tuple ):
1059+ # we have an axis0 multi-index, handle or raise
1060+ axis = self .axis or 0
1061+ try :
1062+ # fast path for series or for tup devoid of slices
1063+ return self ._get_label (tup , axis = axis )
1064+ except TypeError :
1065+ # slices are unhashable
1066+ pass
1067+ except KeyError as ek :
1068+ # raise KeyError if number of indexers match
1069+ # else IndexingError will be raised
1070+ if len (tup ) <= self .obj .index .nlevels and len (tup ) > self .ndim :
1071+ raise ek
1072+
1073+ return None
1074+
10721075 def _getitem_axis (self , key , axis : int ):
10731076 key = item_from_zerodim (key )
10741077 if is_iterator (key ):
0 commit comments