Skip to content

CLN: de-duplicate _getitem_scalar #30992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,12 +1743,14 @@ def _get_slice_axis(self, slice_obj: slice, axis: int):


class _LocationIndexer(_NDFrameIndexer):
_takeable: bool = False

def __getitem__(self, key):
if type(key) is tuple:
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
if self._is_scalar_access(key):
try:
return self._getitem_scalar(key)
return self.obj._get_value(*key, takeable=self._takeable)
except (KeyError, IndexError, AttributeError):
# AttributeError for IntervalTree get_value
pass
Expand All @@ -1763,9 +1765,6 @@ def __getitem__(self, key):
def _is_scalar_access(self, key: Tuple):
raise NotImplementedError()

def _getitem_scalar(self, key):
raise NotImplementedError()

def _getitem_axis(self, key, axis: int):
raise NotImplementedError()

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

return True

def _getitem_scalar(self, key):
# a fast-path to scalar access
# if not, raise
values = self.obj._get_value(*key)
return values

def _get_partial_string_timestamp_match_key(self, key, labels):
"""
Translate any partial string timestamp matches in key, returning the
Expand Down Expand Up @@ -1965,6 +1958,7 @@ class _iLocIndexer(_LocationIndexer):
"point is EXCLUDED), listlike of integers, boolean array"
)
_get_slice_axis = _NDFrameIndexer._get_slice_axis
_takeable = True

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

return True

def _getitem_scalar(self, key):
# a fast-path to scalar access
# if not, raise
values = self.obj._get_value(*key, takeable=True)
return values

def _validate_integer(self, key: int, axis: int) -> None:
"""
Check that 'key' is a valid position in the desired axis.
Expand Down