Skip to content

Commit 13b22fd

Browse files
jbrockmendeljreback
authored andcommitted
CLN: de-duplicate _getitem_scalar (#30992)
1 parent 8ff2ebd commit 13b22fd

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

pandas/core/indexing.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -1743,12 +1743,14 @@ def _get_slice_axis(self, slice_obj: slice, axis: int):
17431743

17441744

17451745
class _LocationIndexer(_NDFrameIndexer):
1746+
_takeable: bool = False
1747+
17461748
def __getitem__(self, key):
17471749
if type(key) is tuple:
17481750
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
17491751
if self._is_scalar_access(key):
17501752
try:
1751-
return self._getitem_scalar(key)
1753+
return self.obj._get_value(*key, takeable=self._takeable)
17521754
except (KeyError, IndexError, AttributeError):
17531755
# AttributeError for IntervalTree get_value
17541756
pass
@@ -1763,9 +1765,6 @@ def __getitem__(self, key):
17631765
def _is_scalar_access(self, key: Tuple):
17641766
raise NotImplementedError()
17651767

1766-
def _getitem_scalar(self, key):
1767-
raise NotImplementedError()
1768-
17691768
def _getitem_axis(self, key, axis: int):
17701769
raise NotImplementedError()
17711770

@@ -1854,12 +1853,6 @@ def _is_scalar_access(self, key: Tuple) -> bool:
18541853

18551854
return True
18561855

1857-
def _getitem_scalar(self, key):
1858-
# a fast-path to scalar access
1859-
# if not, raise
1860-
values = self.obj._get_value(*key)
1861-
return values
1862-
18631856
def _get_partial_string_timestamp_match_key(self, key, labels):
18641857
"""
18651858
Translate any partial string timestamp matches in key, returning the
@@ -1965,6 +1958,7 @@ class _iLocIndexer(_LocationIndexer):
19651958
"point is EXCLUDED), listlike of integers, boolean array"
19661959
)
19671960
_get_slice_axis = _NDFrameIndexer._get_slice_axis
1961+
_takeable = True
19681962

19691963
def _validate_key(self, key, axis: int):
19701964
if com.is_bool_indexer(key):
@@ -2029,12 +2023,6 @@ def _is_scalar_access(self, key: Tuple) -> bool:
20292023

20302024
return True
20312025

2032-
def _getitem_scalar(self, key):
2033-
# a fast-path to scalar access
2034-
# if not, raise
2035-
values = self.obj._get_value(*key, takeable=True)
2036-
return values
2037-
20382026
def _validate_integer(self, key: int, axis: int) -> None:
20392027
"""
20402028
Check that 'key' is a valid position in the desired axis.

0 commit comments

Comments
 (0)