From 2b224039926e4509626e64ed61969117a5330b85 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 28 Dec 2021 09:28:41 -0800 Subject: [PATCH] REF: de-duplicate DataFrame indexing code --- pandas/core/frame.py | 8 +++----- pandas/tests/generic/test_duplicate_labels.py | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 257916630e457..9ef6bda6f63af 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3865,7 +3865,7 @@ def _set_value( loc = self.index.get_loc(index) validate_numeric_casting(series.dtype, value) - series._values[loc] = value + series._mgr.setitem_inplace(loc, value) # Note: trying to use series._set_value breaks tests in # tests.frame.indexing.test_indexing and tests.indexing.test_partial except (KeyError, TypeError): @@ -3908,7 +3908,7 @@ def _box_col_values(self, values: SingleDataManager, loc: int) -> Series: name = self.columns[loc] klass = self._constructor_sliced # We get index=self.index bc values is a SingleDataManager - return klass(values, name=name, fastpath=True) + return klass(values, name=name, fastpath=True).__finalize__(self) # ---------------------------------------------------------------------- # Lookup Caching @@ -3925,11 +3925,9 @@ def _get_item_cache(self, item: Hashable) -> Series: # pending resolution of GH#33047 loc = self.columns.get_loc(item) - col_mgr = self._mgr.iget(loc) - res = self._box_col_values(col_mgr, loc).__finalize__(self) + res = self._ixs(loc, axis=1) cache[item] = res - res._set_as_cached(item, self) # for a chain res._is_copy = self._is_copy diff --git a/pandas/tests/generic/test_duplicate_labels.py b/pandas/tests/generic/test_duplicate_labels.py index 1c0ae46aa5500..43cd3039870d0 100644 --- a/pandas/tests/generic/test_duplicate_labels.py +++ b/pandas/tests/generic/test_duplicate_labels.py @@ -316,9 +316,7 @@ def test_series_raises(self): pytest.param( operator.itemgetter((0, [0, 0])), "iloc", marks=not_implemented ), - pytest.param( - operator.itemgetter(([0, 0], 0)), "iloc", marks=not_implemented - ), + pytest.param(operator.itemgetter(([0, 0], 0)), "iloc"), ], ) def test_getitem_raises(self, getter, target):