@@ -4621,34 +4621,31 @@ def argsort(self, *args, **kwargs) -> np.ndarray:
4621
4621
@Appender (_index_shared_docs ["get_value" ] % _index_doc_kwargs )
4622
4622
def get_value (self , series , key ):
4623
4623
4624
+ if not is_scalar (key ):
4625
+ # if key is not a scalar, directly raise an error (the code below
4626
+ # would convert to numpy arrays and raise later any way) - GH29926
4627
+ raise InvalidIndexError (key )
4628
+
4624
4629
# if we have something that is Index-like, then
4625
4630
# use this, e.g. DatetimeIndex
4626
4631
# Things like `Series._get_value` (via .at) pass the EA directly here.
4627
4632
s = extract_array (series , extract_numpy = True )
4628
4633
if isinstance (s , ExtensionArray ):
4629
- if is_scalar (key ):
4630
- # GH 20882, 21257
4631
- # First try to convert the key to a location
4632
- # If that fails, raise a KeyError if an integer
4633
- # index, otherwise, see if key is an integer, and
4634
- # try that
4635
- try :
4636
- iloc = self .get_loc (key )
4637
- return s [iloc ]
4638
- except KeyError :
4639
- if len (self ) > 0 and (self .holds_integer () or self .is_boolean ()):
4640
- raise
4641
- elif is_integer (key ):
4642
- return s [key ]
4643
- else :
4644
- # if key is not a scalar, directly raise an error (the code below
4645
- # would convert to numpy arrays and raise later any way) - GH29926
4646
- raise InvalidIndexError (key )
4647
-
4648
- s = com .values_from_object (series )
4649
- k = com .values_from_object (key )
4634
+ # GH 20882, 21257
4635
+ # First try to convert the key to a location
4636
+ # If that fails, raise a KeyError if an integer
4637
+ # index, otherwise, see if key is an integer, and
4638
+ # try that
4639
+ try :
4640
+ iloc = self .get_loc (key )
4641
+ return s [iloc ]
4642
+ except KeyError :
4643
+ if len (self ) > 0 and (self .holds_integer () or self .is_boolean ()):
4644
+ raise
4645
+ elif is_integer (key ):
4646
+ return s [key ]
4650
4647
4651
- k = self ._convert_scalar_indexer (k , kind = "getitem" )
4648
+ k = self ._convert_scalar_indexer (key , kind = "getitem" )
4652
4649
try :
4653
4650
return self ._engine .get_value (s , k , tz = getattr (series .dtype , "tz" , None ))
4654
4651
except KeyError as e1 :
0 commit comments