Skip to content

Commit 4485f15

Browse files
authored
TST: Add test for loc not updating cache correctly (#47949)
* TST: Add test for loc not updating cache correctly * Add comment
1 parent 6e998a6 commit 4485f15

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
@@ -1317,6 +1317,29 @@ def test_iloc_setitem_enlarge_no_warning(self):
13171317
df.iloc[:, 0] = np.array([1, 2], dtype=np.float64)
13181318
tm.assert_frame_equal(view, expected)
13191319

1320+
def test_loc_internals_not_updated_correctly(self):
1321+
# GH#47867 all steps are necessary to reproduce the initial bug
1322+
df = DataFrame(
1323+
{"bool_col": True, "a": 1, "b": 2.5},
1324+
index=MultiIndex.from_arrays([[1, 2], [1, 2]], names=["idx1", "idx2"]),
1325+
)
1326+
idx = [(1, 1)]
1327+
1328+
df["c"] = 3
1329+
df.loc[idx, "c"] = 0
1330+
1331+
df.loc[idx, "c"]
1332+
df.loc[idx, ["a", "b"]]
1333+
1334+
df.loc[idx, "c"] = 15
1335+
result = df.loc[idx, "c"]
1336+
expected = df = Series(
1337+
15,
1338+
index=MultiIndex.from_arrays([[1], [1]], names=["idx1", "idx2"]),
1339+
name="c",
1340+
)
1341+
tm.assert_series_equal(result, expected)
1342+
13201343

13211344
class TestDataFrameIndexingUInt64:
13221345
def test_setitem(self, uint64_frame):

0 commit comments

Comments
 (0)