@@ -577,18 +577,6 @@ def __call__(self, axis=None):
577
577
new_self .axis = axis
578
578
return new_self
579
579
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
-
592
580
def _get_setitem_indexer (self , key ):
593
581
"""
594
582
Convert a potentially-label-based key into a positional indexer.
@@ -700,23 +688,6 @@ def _convert_tuple(self, key, is_setter: bool = False):
700
688
keyidx .append (idx )
701
689
return tuple (keyidx )
702
690
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
-
720
691
def _getitem_tuple_same_dim (self , tup : Tuple ):
721
692
"""
722
693
Index with indexers that should return an object of the same dimension
@@ -798,6 +769,9 @@ def _getitem_nested_tuple(self, tup: Tuple):
798
769
# multi-index dimension, try to see if we have something like
799
770
# a tuple passed to a series with a multi-index
800
771
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" )
801
775
result = self ._handle_lowerdim_multi_index_axis0 (tup )
802
776
if result is not None :
803
777
return result
@@ -1069,6 +1043,35 @@ def _getitem_tuple(self, tup: Tuple):
1069
1043
1070
1044
return self ._getitem_tuple_same_dim (tup )
1071
1045
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
+
1072
1075
def _getitem_axis (self , key , axis : int ):
1073
1076
key = item_from_zerodim (key )
1074
1077
if is_iterator (key ):
0 commit comments