@@ -3136,7 +3136,8 @@ def _convert_scalar_indexer(self, key, kind=None):
3136
3136
assert kind in ["loc" , "getitem" , "iloc" , None ]
3137
3137
3138
3138
if kind == "iloc" :
3139
- return self ._validate_indexer ("positional" , key , kind )
3139
+ self ._validate_indexer ("positional" , key , "iloc" )
3140
+ return key
3140
3141
3141
3142
if len (self ) and not isinstance (self , ABCMultiIndex ):
3142
3143
@@ -3145,11 +3146,11 @@ def _convert_scalar_indexer(self, key, kind=None):
3145
3146
# or label indexing if we are using a type able
3146
3147
# to be represented in the index
3147
3148
3148
- if kind in [ "getitem" ] and is_float (key ):
3149
+ if kind == "getitem" and is_float (key ):
3149
3150
if not self .is_floating ():
3150
3151
self ._invalid_indexer ("label" , key )
3151
3152
3152
- elif kind in [ "loc" ] and is_float (key ):
3153
+ elif kind == "loc" and is_float (key ):
3153
3154
3154
3155
# we want to raise KeyError on string/mixed here
3155
3156
# technically we *could* raise a TypeError
@@ -3163,7 +3164,7 @@ def _convert_scalar_indexer(self, key, kind=None):
3163
3164
]:
3164
3165
self ._invalid_indexer ("label" , key )
3165
3166
3166
- elif kind in [ "loc" ] and is_integer (key ):
3167
+ elif kind == "loc" and is_integer (key ):
3167
3168
if not self .holds_integer ():
3168
3169
self ._invalid_indexer ("label" , key )
3169
3170
@@ -3189,11 +3190,10 @@ def _convert_slice_indexer(self, key: slice, kind=None):
3189
3190
3190
3191
# validate iloc
3191
3192
if kind == "iloc" :
3192
- return slice (
3193
- self ._validate_indexer ("slice" , key .start , kind ),
3194
- self ._validate_indexer ("slice" , key .stop , kind ),
3195
- self ._validate_indexer ("slice" , key .step , kind ),
3196
- )
3193
+ self ._validate_indexer ("slice" , key .start , "iloc" )
3194
+ self ._validate_indexer ("slice" , key .stop , "iloc" )
3195
+ self ._validate_indexer ("slice" , key .step , "iloc" )
3196
+ return key
3197
3197
3198
3198
# potentially cast the bounds to integers
3199
3199
start , stop , step = key .start , key .stop , key .step
@@ -3214,11 +3214,10 @@ def is_int(v):
3214
3214
integers
3215
3215
"""
3216
3216
if self .is_integer () or is_index_slice :
3217
- return slice (
3218
- self ._validate_indexer ("slice" , key .start , kind ),
3219
- self ._validate_indexer ("slice" , key .stop , kind ),
3220
- self ._validate_indexer ("slice" , key .step , kind ),
3221
- )
3217
+ self ._validate_indexer ("slice" , key .start , "getitem" )
3218
+ self ._validate_indexer ("slice" , key .stop , "getitem" )
3219
+ self ._validate_indexer ("slice" , key .step , "getitem" )
3220
+ return key
3222
3221
3223
3222
# convert the slice to an indexer here
3224
3223
@@ -3348,7 +3347,7 @@ def _convert_list_indexer(self, keyarr, kind=None):
3348
3347
3349
3348
return None
3350
3349
3351
- def _invalid_indexer (self , form , key ):
3350
+ def _invalid_indexer (self , form : str_t , key ):
3352
3351
"""
3353
3352
Consistent invalid indexer message.
3354
3353
"""
@@ -5006,20 +5005,19 @@ def _maybe_cast_indexer(self, key):
5006
5005
pass
5007
5006
return key
5008
5007
5009
- def _validate_indexer (self , form , key , kind : str_t ):
5008
+ def _validate_indexer (self , form : str_t , key , kind : str_t ):
5010
5009
"""
5011
5010
If we are positional indexer, validate that we have appropriate
5012
5011
typed bounds must be an integer.
5013
5012
"""
5014
- assert kind in ["loc" , " getitem" , "iloc" ]
5013
+ assert kind in ["getitem" , "iloc" ]
5015
5014
5016
5015
if key is None :
5017
5016
pass
5018
5017
elif is_integer (key ):
5019
5018
pass
5020
- elif kind in [ "iloc" , "getitem" ] :
5019
+ else :
5021
5020
self ._invalid_indexer (form , key )
5022
- return key
5023
5021
5024
5022
_index_shared_docs [
5025
5023
"_maybe_cast_slice_bound"
@@ -5044,7 +5042,7 @@ def _validate_indexer(self, form, key, kind: str_t):
5044
5042
"""
5045
5043
5046
5044
@Appender (_index_shared_docs ["_maybe_cast_slice_bound" ])
5047
- def _maybe_cast_slice_bound (self , label , side , kind ):
5045
+ def _maybe_cast_slice_bound (self , label , side : str_t , kind ):
5048
5046
assert kind in ["loc" , "getitem" , None ]
5049
5047
5050
5048
# We are a plain index here (sub-class override this method if they
@@ -5075,7 +5073,7 @@ def _searchsorted_monotonic(self, label, side="left"):
5075
5073
5076
5074
raise ValueError ("index must be monotonic increasing or decreasing" )
5077
5075
5078
- def get_slice_bound (self , label , side , kind ) -> int :
5076
+ def get_slice_bound (self , label , side : str_t , kind ) -> int :
5079
5077
"""
5080
5078
Calculate slice bound that corresponds to given label.
5081
5079
@@ -5260,7 +5258,7 @@ def insert(self, loc: int, item):
5260
5258
idx = np .concatenate ((_self [:loc ], item , _self [loc :]))
5261
5259
return self ._shallow_copy_with_infer (idx )
5262
5260
5263
- def drop (self , labels , errors = "raise" ):
5261
+ def drop (self , labels , errors : str_t = "raise" ):
5264
5262
"""
5265
5263
Make new Index with passed list of labels deleted.
5266
5264
0 commit comments