@@ -2597,25 +2597,16 @@ def _should_fallback_to_positional(self) -> bool:
2597
2597
# GH#33355
2598
2598
return self .levels [0 ]._should_fallback_to_positional
2599
2599
2600
- def _get_values_for_loc (self , series : Series , loc , key ):
2600
+ def get_loc_result_index (self , loc , key ):
2601
2601
"""
2602
- Do a positional lookup on the given Series, returning either a scalar
2603
- or a Series.
2602
+ Find the index to attach to the result of a Series.loc lookup.
2604
2603
2605
- Assumes that `series.index is self`
2606
- """
2607
- new_values = series ._values [loc ]
2608
- if is_scalar (loc ):
2609
- return new_values
2610
-
2611
- if len (new_values ) == 1 and not self .nlevels > 1 :
2612
- # If more than one level left, we can not return a scalar
2613
- return new_values [0 ]
2604
+ Assumes `loc` is not an integer.
2614
2605
2615
- new_index = self [ loc ]
2616
- new_index = maybe_droplevels ( new_index , key )
2617
- new_ser = series . _constructor ( new_values , index = new_index , name = series . name )
2618
- return new_ser . __finalize__ ( series )
2606
+ key is included for MultiIndex compat.
2607
+ """
2608
+ new_index = super (). get_loc_result_index ( loc , key )
2609
+ return maybe_droplevels ( new_index , key )
2619
2610
2620
2611
def _get_indexer_strict (
2621
2612
self , key , axis_name : str
@@ -2922,6 +2913,15 @@ def _maybe_to_slice(loc):
2922
2913
2923
2914
if not isinstance (key , tuple ):
2924
2915
loc = self ._get_level_indexer (key , level = 0 )
2916
+ if (
2917
+ self .nlevels == 1
2918
+ and isinstance (loc , slice )
2919
+ and loc .stop - loc .start == 1
2920
+ and loc .step is None
2921
+ ):
2922
+ # e.g. test_multiindex_at_get_one_level
2923
+ # TODO: is this the right level at which to do this check?
2924
+ return loc .start
2925
2925
return _maybe_to_slice (loc )
2926
2926
2927
2927
keylen = len (key )
0 commit comments