Skip to content

REF: de-duplicate DataFrame indexing code #45092

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 1 commit into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/generic/test_duplicate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down