Skip to content

Commit 5401812

Browse files
authored
CLN: unused kwarg, poorly named obj->key (#31226)
* CLN: unused kwarg, poorly named obj->key * lint fixup
1 parent 3e59f7b commit 5401812

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

pandas/core/indexing.py

+30-31
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ def _validate_read_indexer(
15771577
"https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike" # noqa:E501
15781578
)
15791579

1580-
def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
1580+
def _convert_to_indexer(self, key, axis: int):
15811581
"""
15821582
Convert indexing key into something we can use to do actual fancy
15831583
indexing on a ndarray.
@@ -1594,30 +1594,30 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
15941594
"""
15951595
labels = self.obj._get_axis(axis)
15961596

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)
15991599

16001600
# try to find out correct indexer, if not type correct raise
16011601
try:
1602-
obj = self._convert_scalar_indexer(obj, axis)
1602+
key = self._convert_scalar_indexer(key, axis)
16031603
except TypeError:
16041604
# but we will allow setting
16051605
pass
16061606

16071607
# see if we are positional in nature
16081608
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
16101610

1611-
if is_scalar(obj) or isinstance(labels, ABCMultiIndex):
1611+
if is_scalar(key) or isinstance(labels, ABCMultiIndex):
16121612
# Otherwise get_loc will raise InvalidIndexError
16131613

16141614
# if we are a label return me
16151615
try:
1616-
return labels.get_loc(obj)
1616+
return labels.get_loc(key)
16171617
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}
16211621
raise
16221622
except TypeError:
16231623
pass
@@ -1633,33 +1633,33 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
16331633

16341634
if self.name == "loc":
16351635
# always valid
1636-
return {"key": obj}
1636+
return {"key": key}
16371637

1638-
if obj >= self.obj.shape[axis] and not isinstance(labels, ABCMultiIndex):
1638+
if key >= self.obj.shape[axis] and not isinstance(labels, ABCMultiIndex):
16391639
# a positional
16401640
raise ValueError("cannot set by positional indexing with enlargement")
16411641

1642-
return obj
1642+
return key
16431643

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)
16461646

1647-
elif is_list_like_indexer(obj):
1647+
elif is_list_like_indexer(key):
16481648

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()
16521652
return inds
16531653
else:
16541654
# 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]
16561656
else:
16571657
try:
1658-
return labels.get_loc(obj)
1658+
return labels.get_loc(key)
16591659
except LookupError:
16601660
# 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}
16631663
raise
16641664

16651665
def _get_slice_axis(self, slice_obj: slice, axis: int):
@@ -2051,21 +2051,20 @@ def _getitem_axis(self, key, axis: int):
20512051

20522052
return self._get_loc(key, axis=axis)
20532053

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):
20562055
"""
20572056
Much simpler as we only have to deal with our valid types.
20582057
"""
20592058
# 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)
20622061

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)
20652064

20662065
try:
2067-
self._validate_key(obj, axis)
2068-
return obj
2066+
self._validate_key(key, axis)
2067+
return key
20692068
except ValueError:
20702069
raise ValueError(f"Can only index by location with a [{self._valid_types}]")
20712070

0 commit comments

Comments
 (0)