Skip to content

Commit 52c22b2

Browse files
jbrockmendeljreback
authored andcommitted
REF/CLN: Index.get_value wrapping incorrectly (pandas-dev#31125)
1 parent d170cc0 commit 52c22b2

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

pandas/core/indexes/base.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -4639,7 +4639,8 @@ def get_value(self, series, key):
46394639

46404640
k = self._convert_scalar_indexer(key, kind="getitem")
46414641
try:
4642-
return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
4642+
loc = self._engine.get_loc(k)
4643+
46434644
except KeyError as e1:
46444645
if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
46454646
raise
@@ -4648,19 +4649,17 @@ def get_value(self, series, key):
46484649
return libindex.get_value_at(s, key)
46494650
except IndexError:
46504651
raise
4651-
except TypeError:
4652-
# generator/iterator-like
4653-
if is_iterator(key):
4654-
raise InvalidIndexError(key)
4655-
else:
4656-
raise e1
46574652
except Exception:
46584653
raise e1
46594654
except TypeError:
46604655
# e.g. "[False] is an invalid key"
4661-
if is_scalar(key):
4662-
raise IndexError(key)
4663-
raise InvalidIndexError(key)
4656+
raise IndexError(key)
4657+
4658+
else:
4659+
if is_scalar(loc):
4660+
tz = getattr(series.dtype, "tz", None)
4661+
return libindex.get_value_at(s, loc, tz=tz)
4662+
return series.iloc[loc]
46644663

46654664
def set_value(self, arr, key, value):
46664665
"""

pandas/core/series.py

-12
Original file line numberDiff line numberDiff line change
@@ -815,18 +815,6 @@ def __getitem__(self, key):
815815
try:
816816
result = self.index.get_value(self, key)
817817

818-
if not is_scalar(result):
819-
if is_list_like(result) and not isinstance(result, Series):
820-
821-
# we need to box if loc of the key isn't scalar here
822-
# otherwise have inline ndarray/lists
823-
try:
824-
if not is_scalar(self.index.get_loc(key)):
825-
result = self._constructor(
826-
result, index=[key] * len(result), dtype=self.dtype
827-
).__finalize__(self)
828-
except KeyError:
829-
pass
830818
return result
831819
except InvalidIndexError:
832820
pass

0 commit comments

Comments
 (0)