Skip to content

Backport PR #47949 on branch 1.4.x (TST: Add test for loc not updating cache correctly) (#47949) #47954

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
Aug 4, 2022
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ including other versions of pandas.
Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed regression in :func:`concat` materializing :class:`Index` during sorting even if :class:`Index` was already sorted (:issue:`47501`)
- Fixed regression in :meth:`DataFrame.loc` not updating the cache correctly after values were set (:issue:`47867`)
- Fixed regression in setting ``None`` or non-string value into a ``string``-dtype Series using a mask (:issue:`47628`)
-

Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,29 @@ def test_loc_expand_empty_frame_keep_midx_names(self):
)
tm.assert_frame_equal(df, expected)

def test_loc_internals_not_updated_correctly(self):
# GH#47867 all steps are necessary to reproduce the initial bug
df = DataFrame(
{"bool_col": True, "a": 1, "b": 2.5},
index=MultiIndex.from_arrays([[1, 2], [1, 2]], names=["idx1", "idx2"]),
)
idx = [(1, 1)]

df["c"] = 3
df.loc[idx, "c"] = 0

df.loc[idx, "c"]
df.loc[idx, ["a", "b"]]

df.loc[idx, "c"] = 15
result = df.loc[idx, "c"]
expected = df = Series(
15,
index=MultiIndex.from_arrays([[1], [1]], names=["idx1", "idx2"]),
name="c",
)
tm.assert_series_equal(result, expected)


class TestDataFrameIndexingUInt64:
def test_setitem(self, uint64_frame):
Expand Down