@@ -718,6 +718,25 @@ def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
718
718
719
719
return None
720
720
721
+ def _getitem_tuple_same_dim (self , tup : Tuple ):
722
+ """
723
+ Index with indexers that should return an object of the same dimension
724
+ as self.obj.
725
+
726
+ This is only called after a failed call to _getitem_lowerdim.
727
+ """
728
+ retval = self .obj
729
+ for i , key in enumerate (tup ):
730
+ if com .is_null_slice (key ):
731
+ continue
732
+
733
+ retval = getattr (retval , self .name )._getitem_axis (key , axis = i )
734
+ # We should never have retval.ndim < self.ndim, as that should
735
+ # be handled by the _getitem_lowerdim call above.
736
+ assert retval .ndim == self .ndim
737
+
738
+ return retval
739
+
721
740
def _getitem_lowerdim (self , tup : Tuple ):
722
741
723
742
# we can directly get the axis result since the axis is specified
@@ -1049,15 +1068,7 @@ def _getitem_tuple(self, tup: Tuple):
1049
1068
if self ._multi_take_opportunity (tup ):
1050
1069
return self ._multi_take (tup )
1051
1070
1052
- # no shortcut needed
1053
- retval = self .obj
1054
- for i , key in enumerate (tup ):
1055
- if com .is_null_slice (key ):
1056
- continue
1057
-
1058
- retval = getattr (retval , self .name )._getitem_axis (key , axis = i )
1059
-
1060
- return retval
1071
+ return self ._getitem_tuple_same_dim (tup )
1061
1072
1062
1073
def _getitem_axis (self , key , axis : int ):
1063
1074
key = item_from_zerodim (key )
@@ -1468,25 +1479,7 @@ def _getitem_tuple(self, tup: Tuple):
1468
1479
except IndexingError :
1469
1480
pass
1470
1481
1471
- retval = self .obj
1472
- axis = 0
1473
- for i , key in enumerate (tup ):
1474
- if com .is_null_slice (key ):
1475
- axis += 1
1476
- continue
1477
-
1478
- retval = getattr (retval , self .name )._getitem_axis (key , axis = axis )
1479
-
1480
- # if the dim was reduced, then pass a lower-dim the next time
1481
- if retval .ndim < self .ndim :
1482
- # TODO: this is never reached in tests; can we confirm that
1483
- # it is impossible?
1484
- axis -= 1
1485
-
1486
- # try to get for the next axis
1487
- axis += 1
1488
-
1489
- return retval
1482
+ return self ._getitem_tuple_same_dim (tup )
1490
1483
1491
1484
def _get_list_axis (self , key , axis : int ):
1492
1485
"""
0 commit comments