Skip to content

REF: call _convert_scalar_indexer upfront in Series.__getitem__ #31655

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 5, 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
7 changes: 2 additions & 5 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@ def __getitem__(self, key):
return self

key_is_scalar = is_scalar(key)
if key_is_scalar:
key = self.index._convert_scalar_indexer(key, kind="getitem")

if key_is_scalar or isinstance(self.index, MultiIndex):
# Otherwise index.get_value will raise InvalidIndexError
Expand All @@ -866,11 +868,6 @@ def __getitem__(self, key):
# kludge
pass
else:

# we can try to coerce the indexer (or this will raise)
new_key = self.index._convert_scalar_indexer(key, kind="getitem")
if type(new_key) != type(key):
return self.__getitem__(new_key)
raise

if not key_is_scalar:
Expand Down