Skip to content

REF: Move Series logic from Index._get_values_for_loc #47975

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
Oct 24, 2022
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: 19 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
ensure_index,
)
import pandas.core.indexes.base as ibase
from pandas.core.indexes.multi import maybe_droplevels
from pandas.core.indexing import (
check_bool_indexer,
check_deprecated_indexers,
Expand Down Expand Up @@ -1062,7 +1063,24 @@ def _get_value(self, label, takeable: bool = False):

# Similar to Index.get_value, but we do not fall back to positional
loc = self.index.get_loc(label)
return self.index._get_values_for_loc(self, loc, label)

if is_integer(loc):
Copy link
Member

Choose a reason for hiding this comment

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

So since this PR has been opened code is no longer moved from Index._get_values_for_loc?

Copy link
Member Author

Choose a reason for hiding this comment

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

get_values_for_loc can be removed after this. at the time this PR was opened there was another (deprecated) usage

return self._values[loc]

if isinstance(self.index, MultiIndex):
mi = self.index
new_values = self._values[loc]
if len(new_values) == 1 and mi.nlevels == 1:
# If more than one level left, we can not return a scalar
return new_values[0]

new_index = mi[loc]
new_index = maybe_droplevels(new_index, label)
new_ser = self._constructor(new_values, index=new_index, name=self.name)
return new_ser.__finalize__(self)

else:
return self.iloc[loc]

def __setitem__(self, key, value) -> None:
check_deprecated_indexers(key)
Expand Down