@@ -1577,7 +1577,7 @@ def _validate_read_indexer(
1577
1577
"https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike" # noqa:E501
1578
1578
)
1579
1579
1580
- def _convert_to_indexer (self , obj , axis : int , raise_missing : bool = False ):
1580
+ def _convert_to_indexer (self , key , axis : int ):
1581
1581
"""
1582
1582
Convert indexing key into something we can use to do actual fancy
1583
1583
indexing on a ndarray.
@@ -1594,30 +1594,30 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
1594
1594
"""
1595
1595
labels = self .obj ._get_axis (axis )
1596
1596
1597
- if isinstance (obj , slice ):
1598
- return self ._convert_slice_indexer (obj , axis )
1597
+ if isinstance (key , slice ):
1598
+ return self ._convert_slice_indexer (key , axis )
1599
1599
1600
1600
# try to find out correct indexer, if not type correct raise
1601
1601
try :
1602
- obj = self ._convert_scalar_indexer (obj , axis )
1602
+ key = self ._convert_scalar_indexer (key , axis )
1603
1603
except TypeError :
1604
1604
# but we will allow setting
1605
1605
pass
1606
1606
1607
1607
# see if we are positional in nature
1608
1608
is_int_index = labels .is_integer ()
1609
- is_int_positional = is_integer (obj ) and not is_int_index
1609
+ is_int_positional = is_integer (key ) and not is_int_index
1610
1610
1611
- if is_scalar (obj ) or isinstance (labels , ABCMultiIndex ):
1611
+ if is_scalar (key ) or isinstance (labels , ABCMultiIndex ):
1612
1612
# Otherwise get_loc will raise InvalidIndexError
1613
1613
1614
1614
# if we are a label return me
1615
1615
try :
1616
- return labels .get_loc (obj )
1616
+ return labels .get_loc (key )
1617
1617
except LookupError :
1618
- if isinstance (obj , tuple ) and isinstance (labels , ABCMultiIndex ):
1619
- if len (obj ) == labels .nlevels :
1620
- return {"key" : obj }
1618
+ if isinstance (key , tuple ) and isinstance (labels , ABCMultiIndex ):
1619
+ if len (key ) == labels .nlevels :
1620
+ return {"key" : key }
1621
1621
raise
1622
1622
except TypeError :
1623
1623
pass
@@ -1633,33 +1633,33 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
1633
1633
1634
1634
if self .name == "loc" :
1635
1635
# always valid
1636
- return {"key" : obj }
1636
+ return {"key" : key }
1637
1637
1638
- if obj >= self .obj .shape [axis ] and not isinstance (labels , ABCMultiIndex ):
1638
+ if key >= self .obj .shape [axis ] and not isinstance (labels , ABCMultiIndex ):
1639
1639
# a positional
1640
1640
raise ValueError ("cannot set by positional indexing with enlargement" )
1641
1641
1642
- return obj
1642
+ return key
1643
1643
1644
- if is_nested_tuple (obj , labels ):
1645
- return labels .get_locs (obj )
1644
+ if is_nested_tuple (key , labels ):
1645
+ return labels .get_locs (key )
1646
1646
1647
- elif is_list_like_indexer (obj ):
1647
+ elif is_list_like_indexer (key ):
1648
1648
1649
- if com .is_bool_indexer (obj ):
1650
- obj = check_bool_indexer (labels , obj )
1651
- (inds ,) = obj .nonzero ()
1649
+ if com .is_bool_indexer (key ):
1650
+ key = check_bool_indexer (labels , key )
1651
+ (inds ,) = key .nonzero ()
1652
1652
return inds
1653
1653
else :
1654
1654
# When setting, missing keys are not allowed, even with .loc:
1655
- return self ._get_listlike_indexer (obj , axis , raise_missing = True )[1 ]
1655
+ return self ._get_listlike_indexer (key , axis , raise_missing = True )[1 ]
1656
1656
else :
1657
1657
try :
1658
- return labels .get_loc (obj )
1658
+ return labels .get_loc (key )
1659
1659
except LookupError :
1660
1660
# allow a not found key only if we are a setter
1661
- if not is_list_like_indexer (obj ):
1662
- return {"key" : obj }
1661
+ if not is_list_like_indexer (key ):
1662
+ return {"key" : key }
1663
1663
raise
1664
1664
1665
1665
def _get_slice_axis (self , slice_obj : slice , axis : int ):
@@ -2051,21 +2051,20 @@ def _getitem_axis(self, key, axis: int):
2051
2051
2052
2052
return self ._get_loc (key , axis = axis )
2053
2053
2054
- # raise_missing is included for compat with the parent class signature
2055
- def _convert_to_indexer (self , obj , axis : int , raise_missing : bool = False ):
2054
+ def _convert_to_indexer (self , key , axis : int ):
2056
2055
"""
2057
2056
Much simpler as we only have to deal with our valid types.
2058
2057
"""
2059
2058
# make need to convert a float key
2060
- if isinstance (obj , slice ):
2061
- return self ._convert_slice_indexer (obj , axis )
2059
+ if isinstance (key , slice ):
2060
+ return self ._convert_slice_indexer (key , axis )
2062
2061
2063
- elif is_float (obj ):
2064
- return self ._convert_scalar_indexer (obj , axis )
2062
+ elif is_float (key ):
2063
+ return self ._convert_scalar_indexer (key , axis )
2065
2064
2066
2065
try :
2067
- self ._validate_key (obj , axis )
2068
- return obj
2066
+ self ._validate_key (key , axis )
2067
+ return key
2069
2068
except ValueError :
2070
2069
raise ValueError (f"Can only index by location with a [{ self ._valid_types } ]" )
2071
2070
0 commit comments