Skip to content

Commit 8620b02

Browse files
authored
Backport PR #47949 on branch 1.4.x (TST: Add test for loc not updating cache correctly) (#47949) (#47954)
1 parent 015f67d commit 8620b02

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

doc/source/whatsnew/v1.4.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ including other versions of pandas.
1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717
- Fixed regression in :func:`concat` materializing :class:`Index` during sorting even if :class:`Index` was already sorted (:issue:`47501`)
18+
- Fixed regression in :meth:`DataFrame.loc` not updating the cache correctly after values were set (:issue:`47867`)
1819
- Fixed regression in setting ``None`` or non-string value into a ``string``-dtype Series using a mask (:issue:`47628`)
1920
-
2021

pandas/tests/frame/indexing/test_indexing.py

+23
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,29 @@ def test_loc_expand_empty_frame_keep_midx_names(self):
13001300
)
13011301
tm.assert_frame_equal(df, expected)
13021302

1303+
def test_loc_internals_not_updated_correctly(self):
1304+
# GH#47867 all steps are necessary to reproduce the initial bug
1305+
df = DataFrame(
1306+
{"bool_col": True, "a": 1, "b": 2.5},
1307+
index=MultiIndex.from_arrays([[1, 2], [1, 2]], names=["idx1", "idx2"]),
1308+
)
1309+
idx = [(1, 1)]
1310+
1311+
df["c"] = 3
1312+
df.loc[idx, "c"] = 0
1313+
1314+
df.loc[idx, "c"]
1315+
df.loc[idx, ["a", "b"]]
1316+
1317+
df.loc[idx, "c"] = 15
1318+
result = df.loc[idx, "c"]
1319+
expected = df = Series(
1320+
15,
1321+
index=MultiIndex.from_arrays([[1], [1]], names=["idx1", "idx2"]),
1322+
name="c",
1323+
)
1324+
tm.assert_series_equal(result, expected)
1325+
13031326

13041327
class TestDataFrameIndexingUInt64:
13051328
def test_setitem(self, uint64_frame):

0 commit comments

Comments
 (0)