Skip to content

Commit 5d0f6ed

Browse files
authored
BUG: Frame.iat item_cache invalidation bug (#45706)
1 parent 4451392 commit 5d0f6ed

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

doc/source/whatsnew/v1.4.1.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ Fixed regressions
1717
- Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`)
1818
- Regression in :func:`.assert_frame_equal` not respecting ``check_flags=False`` (:issue:`45554`)
1919
- Regression in :meth:`Series.fillna` with ``downcast=False`` incorrectly downcasting ``object`` dtype (:issue:`45603`)
20+
- Regression in :meth:`DataFrame.iat` setting values leading to not propagating correctly in subsequent lookups (:issue:`45684`)
2021
- Regression in :meth:`DataFrame.loc.__setitem__` losing :class:`Index` name if :class:`DataFrame` was empty before (:issue:`45621`)
2122
- Regression in :func:`join` with overlapping :class:`IntervalIndex` raising an ``InvalidIndexError`` (:issue:`45661`)
22-
-
23+
2324

2425
.. ---------------------------------------------------------------------------
2526

pandas/core/frame.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -3876,15 +3876,15 @@ def _set_value(
38763876
try:
38773877
if takeable:
38783878
series = self._ixs(col, axis=1)
3879-
series._set_value(index, value, takeable=True)
3880-
return
3881-
3882-
series = self._get_item_cache(col)
3883-
loc = self.index.get_loc(index)
3879+
loc = index
3880+
else:
3881+
series = self._get_item_cache(col)
3882+
loc = self.index.get_loc(index)
38843883

3885-
# series._set_value will do validation that may raise TypeError
3884+
# setitem_inplace will do validation that may raise TypeError
38863885
# or ValueError
3887-
series._set_value(loc, value, takeable=True)
3886+
series._mgr.setitem_inplace(loc, value)
3887+
38883888
except (KeyError, TypeError, ValueError):
38893889
# set using a non-recursive method & reset the cache
38903890
if takeable:

pandas/tests/indexing/test_iat.py

+17
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ def test_iat_getitem_series_with_period_index():
2929
expected = ser[index[0]]
3030
result = ser.iat[0]
3131
assert expected == result
32+
33+
34+
def test_iat_setitem_item_cache_cleared(indexer_ial):
35+
# GH#45684
36+
data = {"x": np.arange(8, dtype=np.int64), "y": np.int64(0)}
37+
df = DataFrame(data).copy()
38+
ser = df["y"]
39+
40+
# previously this iat setting would split the block and fail to clear
41+
# the item_cache.
42+
indexer_ial(df)[7, 0] = 9999
43+
44+
indexer_ial(df)[7, 1] = 1234
45+
46+
assert df.iat[7, 1] == 1234
47+
assert ser.iloc[-1] == 1234
48+
assert df.iloc[-1, -1] == 1234

0 commit comments

Comments
 (0)