Skip to content

REF/CLN: Index.get_value wrapping incorrectly #31125

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 18, 2020
Merged
Show file tree
Hide file tree
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
19 changes: 9 additions & 10 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4639,7 +4639,8 @@ def get_value(self, series, key):

k = self._convert_scalar_indexer(key, kind="getitem")
try:
return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
loc = self._engine.get_loc(k)

except KeyError as e1:
if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
raise
Expand All @@ -4648,19 +4649,17 @@ def get_value(self, series, key):
return libindex.get_value_at(s, key)
except IndexError:
raise
except TypeError:
# generator/iterator-like
if is_iterator(key):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we just have no tests which hit this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be caught by the not is_scalar(key) check that we recently moved to the beginning of this method

raise InvalidIndexError(key)
else:
raise e1
except Exception:
raise e1
except TypeError:
# e.g. "[False] is an invalid key"
if is_scalar(key):
raise IndexError(key)
raise InvalidIndexError(key)
raise IndexError(key)

else:
if is_scalar(loc):
tz = getattr(series.dtype, "tz", None)
return libindex.get_value_at(s, loc, tz=tz)
return series.iloc[loc]

def set_value(self, arr, key, value):
"""
Expand Down
12 changes: 0 additions & 12 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,18 +815,6 @@ def __getitem__(self, key):
try:
result = self.index.get_value(self, key)

if not is_scalar(result):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can just return directly here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah, we return result on the next line

if is_list_like(result) and not isinstance(result, Series):

# we need to box if loc of the key isn't scalar here
# otherwise have inline ndarray/lists
try:
if not is_scalar(self.index.get_loc(key)):
result = self._constructor(
result, index=[key] * len(result), dtype=self.dtype
).__finalize__(self)
except KeyError:
pass
return result
except InvalidIndexError:
pass
Expand Down