11import textwrap
2+ from typing import Tuple
23import warnings
34
45import numpy as np
@@ -936,7 +937,7 @@ def _getitem_lowerdim(self, tup):
936937 new_key = b , a
937938
938939 if len (new_key ) == 1 :
939- new_key , = new_key
940+ new_key = new_key [ 0 ]
940941
941942 # Slices should return views, but calling iloc/loc with a null
942943 # slice returns a new object.
@@ -1250,7 +1251,7 @@ def _convert_to_indexer(
12501251 # a positional
12511252 if obj >= self .obj .shape [axis ] and not isinstance (labels , MultiIndex ):
12521253 raise ValueError (
1253- "cannot set by positional indexing with " " enlargement"
1254+ "cannot set by positional indexing with enlargement"
12541255 )
12551256
12561257 return obj
@@ -1408,7 +1409,7 @@ def __getitem__(self, key):
14081409 maybe_callable = com .apply_if_callable (key , self .obj )
14091410 return self ._getitem_axis (maybe_callable , axis = axis )
14101411
1411- def _is_scalar_access (self , key ):
1412+ def _is_scalar_access (self , key : Tuple ):
14121413 raise NotImplementedError ()
14131414
14141415 def _getitem_scalar (self , key ):
@@ -1709,14 +1710,11 @@ def _validate_key(self, key, axis: int):
17091710 if not is_list_like_indexer (key ):
17101711 self ._convert_scalar_indexer (key , axis )
17111712
1712- def _is_scalar_access (self , key ):
1713+ def _is_scalar_access (self , key : Tuple ):
17131714 # this is a shortcut accessor to both .loc and .iloc
17141715 # that provide the equivalent access of .at and .iat
17151716 # a) avoid getting things via sections and (to minimize dtype changes)
17161717 # b) provide a performant path
1717- if not hasattr (key , "__len__" ):
1718- return False
1719-
17201718 if len (key ) != self .ndim :
17211719 return False
17221720
@@ -2000,7 +1998,7 @@ def _validate_key(self, key, axis: int):
20001998 # check that the key has a numeric dtype
20011999 if not is_numeric_dtype (arr .dtype ):
20022000 raise IndexError (
2003- ".iloc requires numeric indexers, got " " {arr}" .format (arr = arr )
2001+ ".iloc requires numeric indexers, got {arr}" .format (arr = arr )
20042002 )
20052003
20062004 # check that the key does not exceed the maximum size of the index
@@ -2015,14 +2013,11 @@ def _validate_key(self, key, axis: int):
20152013 def _has_valid_setitem_indexer (self , indexer ):
20162014 self ._has_valid_positional_setitem_indexer (indexer )
20172015
2018- def _is_scalar_access (self , key ):
2016+ def _is_scalar_access (self , key : Tuple ):
20192017 # this is a shortcut accessor to both .loc and .iloc
20202018 # that provide the equivalent access of .at and .iat
20212019 # a) avoid getting things via sections and (to minimize dtype changes)
20222020 # b) provide a performant path
2023- if not hasattr (key , "__len__" ):
2024- return False
2025-
20262021 if len (key ) != self .ndim :
20272022 return False
20282023
@@ -2131,9 +2126,7 @@ def _getitem_axis(self, key, axis: int):
21312126 else :
21322127 key = item_from_zerodim (key )
21332128 if not is_integer (key ):
2134- raise TypeError (
2135- "Cannot index by location index with a " "non-integer key"
2136- )
2129+ raise TypeError ("Cannot index by location index with a non-integer key" )
21372130
21382131 # validate the location
21392132 self ._validate_integer (key , axis )
@@ -2191,7 +2184,7 @@ def __setitem__(self, key, value):
21912184 if not isinstance (key , tuple ):
21922185 key = self ._tuplify (key )
21932186 if len (key ) != self .obj .ndim :
2194- raise ValueError ("Not enough indexers for scalar access " " (setting)!" )
2187+ raise ValueError ("Not enough indexers for scalar access (setting)!" )
21952188 key = list (self ._convert_key (key , is_setter = True ))
21962189 key .append (value )
21972190 self .obj ._set_value (* key , takeable = self ._takeable )
@@ -2327,7 +2320,7 @@ def _convert_key(self, key, is_setter: bool = False):
23272320 """ require integer args (and convert to label arguments) """
23282321 for a , i in zip (self .obj .axes , key ):
23292322 if not is_integer (i ):
2330- raise ValueError ("iAt based indexing can only have integer " " indexers" )
2323+ raise ValueError ("iAt based indexing can only have integer indexers" )
23312324 return key
23322325
23332326
0 commit comments