@@ -177,7 +177,7 @@ def _get_setitem_indexer(self, key):
177
177
178
178
try :
179
179
return self ._convert_to_indexer (key , is_setter = True )
180
- except TypeError as e :
180
+ except ValueError as e :
181
181
182
182
# invalid indexer type vs 'other' indexing errors
183
183
if 'cannot do' in str (e ):
@@ -2090,8 +2090,8 @@ def _validate_key(self, key, axis):
2090
2090
if len (arr ) and (arr .max () >= l or arr .min () < - l ):
2091
2091
raise IndexError ("positional indexers are out-of-bounds" )
2092
2092
else :
2093
- raise ValueError ("Can only index by location with "
2094
- "a [{types}]" .format (types = self ._valid_types ))
2093
+ raise TypeError ("Can only index by location with "
2094
+ "a [{types}]" .format (types = self ._valid_types ))
2095
2095
2096
2096
def _has_valid_setitem_indexer (self , indexer ):
2097
2097
self ._has_valid_positional_setitem_indexer (indexer )
@@ -2242,24 +2242,31 @@ def _getitem_axis(self, key, axis=None):
2242
2242
2243
2243
return self ._get_loc (key , axis = axis )
2244
2244
2245
- def _convert_to_indexer (self , obj , axis = None , is_setter = False ):
2246
- """ much simpler as we only have to deal with our valid types """
2247
- if axis is None :
2248
- axis = self . axis or 0
2245
+ def _convert_to_indexer (self , key , axis = None , is_setter = False ):
2246
+ """
2247
+ iloc needs no conversion of keys: this method is for compatibility
2248
+ with other indexer types, and only validates the key.
2249
2249
2250
- # make need to convert a float key
2251
- if isinstance (obj , slice ):
2252
- return self ._convert_slice_indexer (obj , axis )
2250
+ Parameters
2251
+ ----------
2252
+ key : int, int slice, listlike of integers, or boolean array
2253
+ A valid key for iloc
2254
+ axis : int
2255
+ Dimension on which the indexing is being made
2253
2256
2254
- elif is_float (obj ):
2255
- return self ._convert_scalar_indexer (obj , axis )
2257
+ Returns
2258
+ -------
2259
+ 'key' itself
2256
2260
2257
- try :
2258
- self ._validate_key (obj , axis )
2259
- return obj
2260
- except ValueError :
2261
- raise ValueError ("Can only index by location with "
2262
- "a [{types}]" .format (types = self ._valid_types ))
2261
+ Raises
2262
+ ------
2263
+ Same as _iLocIndexer._validate_key()
2264
+ """
2265
+ if axis is None :
2266
+ axis = self .axis or 0
2267
+
2268
+ self ._validate_key (key , axis )
2269
+ return key
2263
2270
2264
2271
2265
2272
class _ScalarAccessIndexer (_NDFrameIndexer ):
0 commit comments