From 03195e14488000cd2b7cfd5ab5e95129d39d7318 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 30 Aug 2022 21:38:56 -0400 Subject: [PATCH 1/2] BUG: Add note in whatsnew for DataFrame.at behavior change --- doc/source/whatsnew/v1.5.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 711352775400e..54faa70535043 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -1080,7 +1080,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 ^^^^^^^ From 372b35c8b9fdf306559f078b67965ecfacea82f7 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 31 Aug 2022 21:22:54 -0400 Subject: [PATCH 2/2] Add test --- pandas/tests/indexing/test_at.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/indexing/test_at.py b/pandas/tests/indexing/test_at.py index 96c73b007cef3..1e502ca70189a 100644 --- a/pandas/tests/indexing/test_at.py +++ b/pandas/tests/indexing/test_at.py @@ -6,6 +6,8 @@ import numpy as np import pytest +from pandas.errors import InvalidIndexError + from pandas import ( CategoricalDtype, CategoricalIndex, @@ -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])