8000 REGR: Series access with Index of tuples/frozenset by rhshadrach · Pull Request #36147 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REGR: Series access with Index of tuples/frozenset #36147

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 12 commits into from
Sep 12, 2020
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
rhshadrach committed Sep 5, 2020
commit aa2d1d4e473bd39826ec75f46248192107d012fe
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,6 @@ def __getitem__(self, key):
elif key_is_scalar:
return self._get_value(key)

# if isinstance(key, tuple) and is_hashable(key):
if not is_iterator(key) and is_hashable(key):
# Otherwise index.get_value will raise InvalidIndexError
if isinstance(self.index, MultiIndex):
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of doing the if first, can you do it in the keyerror itself e.g.

try:
    result = self._get_value(key)
    return result
except KeyError:
    if isinstance(self.index, MultiIndex):
        return self._get_values_tuple(key)

of course maybe we should actually do this inside _get_value

Copy link
Member Author
@rhshadrach rhshadrach Sep 7, 2020

Choose a reason for hiding this comment

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

Since _get_value is called from 4 places, I'll look into doing this for 1.2 in a followup.

Expand All @@ -900,6 +899,7 @@ def __getitem__(self, key):
# in the first level of our MultiIndex
return self._get_values_tuple(key)
else:
# No fallback for an Index
return self._get_value(key)

if is_iterator(key):
Expand Down
0