diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 10b605f6ef43e..1604d5d1950d7 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -17,9 +17,10 @@ Fixed regressions - Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`) - Regression in :func:`.assert_frame_equal` not respecting ``check_flags=False`` (:issue:`45554`) - Regression in :meth:`Series.fillna` with ``downcast=False`` incorrectly downcasting ``object`` dtype (:issue:`45603`) +- Regression in :meth:`DataFrame.iat` setting values leading to not propagating correctly in subsequent lookups (:issue:`45684`) - Regression in :meth:`DataFrame.loc.__setitem__` losing :class:`Index` name if :class:`DataFrame` was empty before (:issue:`45621`) - Regression in :func:`join` with overlapping :class:`IntervalIndex` raising an ``InvalidIndexError`` (:issue:`45661`) -- + .. --------------------------------------------------------------------------- diff --git a/pandas/core/frame.py b/pandas/core/frame.py index eb2f734165ee9..48649174ce646 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3876,15 +3876,15 @@ def _set_value( try: if takeable: series = self._ixs(col, axis=1) - series._set_value(index, value, takeable=True) - return - - series = self._get_item_cache(col) - loc = self.index.get_loc(index) + loc = index + else: + series = self._get_item_cache(col) + loc = self.index.get_loc(index) - # series._set_value will do validation that may raise TypeError + # setitem_inplace will do validation that may raise TypeError # or ValueError - series._set_value(loc, value, takeable=True) + series._mgr.setitem_inplace(loc, value) + except (KeyError, TypeError, ValueError): # set using a non-recursive method & reset the cache if takeable: diff --git a/pandas/tests/indexing/test_iat.py b/pandas/tests/indexing/test_iat.py index f1fe464ca0854..44bd51ee1b7d1 100644 --- a/pandas/tests/indexing/test_iat.py +++ b/pandas/tests/indexing/test_iat.py @@ -29,3 +29,20 @@ def test_iat_getitem_series_with_period_index(): expected = ser[index[0]] result = ser.iat[0] assert expected == result + + +def test_iat_setitem_item_cache_cleared(indexer_ial): + # GH#45684 + data = {"x": np.arange(8, dtype=np.int64), "y": np.int64(0)} + df = DataFrame(data).copy() + ser = df["y"] + + # previously this iat setting would split the block and fail to clear + # the item_cache. + indexer_ial(df)[7, 0] = 9999 + + indexer_ial(df)[7, 1] = 1234 + + assert df.iat[7, 1] == 1234 + assert ser.iloc[-1] == 1234 + assert df.iloc[-1, -1] == 1234