Skip to content

BUG: Frame.iat item_cache invalidation bug #45706

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 3 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Indexing
- Bug in :meth:`Series.__setitem__` where setting :attr:`NA` into a numeric-dtpye :class:`Series` would incorrectly upcast to object-dtype rather than treating the value as ``np.nan`` (:issue:`44199`)
- Bug in :meth:`DataFrame.mask` with ``inplace=True`` and ``ExtensionDtype`` columns incorrectly raising (:issue:`45577`)
- Bug in getting a column from a DataFrame with an object-dtype row index with datetime-like values: the resulting Series now preserves the exact object-dtype Index from the parent DataFrame (:issue:`42950`)
- Bug in :meth:`DataFrame.iat` setting values leading to not propagating correctly in subsequent lookups (:issue:`45684`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to 1.4.1

- Bug in indexing on a :class:`DatetimeIndex` with a ``np.str_`` key incorrectly raising (:issue:`45580`)
- Bug in :meth:`CategoricalIndex.get_indexer` when index contains ``NaN`` values, resulting in elements that are in target but not present in the index to be mapped to the index of the NaN element, instead of -1 (:issue:`45361`)
-
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3878,15 +3878,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:
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/indexing/test_iat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
# 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.
df.iat[7, 0] = 9999

df.iat[7, 1] = 1234

assert df.iat[7, 1] == 1234
assert ser.iloc[-1] == 1234
assert df.iloc[-1, -1] == 1234