Skip to content
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

Backport PR #48324 on branch 1.5.x (BUG: Add note in whatsnew for DataFrame.at behavior change) #48345

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ Indexing
- Bug in :meth:`DataFrame.sum` min_count changes dtype if input contains NaNs (:issue:`46947`)
- Bug in :class:`IntervalTree` that lead to an infinite recursion. (:issue:`46658`)
- Bug in :class:`PeriodIndex` raising ``AttributeError`` when indexing on ``NA``, rather than putting ``NaT`` in its place. (:issue:`46673`)
-
- Bug in :meth:`DataFrame.at` would allow the modification of multiple columns (:issue:`48296`)

Missing
^^^^^^^
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/indexing/test_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import numpy as np
import pytest

from pandas.errors import InvalidIndexError

from pandas import (
CategoricalDtype,
CategoricalIndex,
Expand Down Expand Up @@ -192,6 +194,12 @@ def test_at_frame_raises_key_error2(self, indexer_al):
with pytest.raises(KeyError, match="^0$"):
indexer_al(df)["a", 0]

def test_at_frame_multiple_columns(self):
# GH#48296 - at shouldn't modify multiple columns
df = DataFrame({"a": [1, 2], "b": [3, 4]})
with pytest.raises(InvalidIndexError, match=r"slice\(None, None, None\)"):
df.at[5] = [6, 7]

def test_at_getitem_mixed_index_no_fallback(self):
# GH#19860
ser = Series([1, 2, 3, 4, 5], index=["a", "b", "c", 1, 2])
Expand Down