Skip to content

Commit dbe0c10

Browse files
authored
REF: Move Series logic from Index._get_values_for_loc (pandas-dev#47975)
* REF: Move Series logic from Index._get_values_for_loc * try again
1 parent fd97a07 commit dbe0c10

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pandas/core/series.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
ensure_index,
141141
)
142142
import pandas.core.indexes.base as ibase
143+
from pandas.core.indexes.multi import maybe_droplevels
143144
from pandas.core.indexing import (
144145
check_bool_indexer,
145146
check_deprecated_indexers,
@@ -1053,7 +1054,24 @@ def _get_value(self, label, takeable: bool = False):
10531054

10541055
# Similar to Index.get_value, but we do not fall back to positional
10551056
loc = self.index.get_loc(label)
1056-
return self.index._get_values_for_loc(self, loc, label)
1057+
1058+
if is_integer(loc):
1059+
return self._values[loc]
1060+
1061+
if isinstance(self.index, MultiIndex):
1062+
mi = self.index
1063+
new_values = self._values[loc]
1064+
if len(new_values) == 1 and mi.nlevels == 1:
1065+
# If more than one level left, we can not return a scalar
1066+
return new_values[0]
1067+
1068+
new_index = mi[loc]
1069+
new_index = maybe_droplevels(new_index, label)
1070+
new_ser = self._constructor(new_values, index=new_index, name=self.name)
1071+
return new_ser.__finalize__(self)
1072+
1073+
else:
1074+
return self.iloc[loc]
10571075

10581076
def __setitem__(self, key, value) -> None:
10591077
check_deprecated_indexers(key)

0 commit comments

Comments
 (0)