Skip to content

CLN: Unreachable branch in Loc._getitem_iterable #31636

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 3 commits into from
Feb 4, 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
37 changes: 11 additions & 26 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,14 +1477,12 @@ def _get_listlike_indexer(self, key, axis: int, raise_missing: bool = False):

def _getitem_iterable(self, key, axis: int):
"""
Index current object with an an iterable key.

The iterable key can be a boolean indexer or a collection of keys.
Index current object with an an iterable collection of keys.

Parameters
----------
key : iterable
Targeted labels or boolean indexer.
Targeted labels.
axis: int
Dimension on which the indexing is being made.

Expand All @@ -1493,30 +1491,20 @@ def _getitem_iterable(self, key, axis: int):
KeyError
If no key was found. Will change in the future to raise if not all
keys were found.
IndexingError
If the boolean indexer is unalignable with the object being
indexed.

Returns
-------
scalar, DataFrame, or Series: indexed value(s).
"""
# caller is responsible for ensuring non-None axis
# we assume that not com.is_bool_indexer(key), as that is
# handled before we get here.
self._validate_key(key, axis)

labels = self.obj._get_axis(axis)

if com.is_bool_indexer(key):
# A boolean indexer
key = check_bool_indexer(labels, key)
(inds,) = key.nonzero()
return self.obj._take_with_is_copy(inds, axis=axis)
else:
# A collection of keys
keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
return self.obj._reindex_with_indexers(
{axis: [keyarr, indexer]}, copy=True, allow_dups=True
)
# A collection of keys
keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
return self.obj._reindex_with_indexers(
{axis: [keyarr, indexer]}, copy=True, allow_dups=True
)

def _validate_read_indexer(
self, key, indexer, axis: int, raise_missing: bool = False
Expand Down Expand Up @@ -2055,11 +2043,8 @@ def _convert_to_indexer(self, key, axis: int):
elif is_float(key):
return self._convert_scalar_indexer(key, axis)

try:
self._validate_key(key, axis)
return key
except ValueError:
raise ValueError(f"Can only index by location with a [{self._valid_types}]")
self._validate_key(key, axis)
return key


class _ScalarAccessIndexer(_NDFrameIndexerBase):
Expand Down