Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
function as nv,
np_percentile_argname,
)
from pandas.errors import InvalidIndexError
from pandas.util._decorators import (
Appender,
Substitution,
Expand Down Expand Up @@ -4239,6 +4240,14 @@ def _set_value(
self.loc[index, col] = value
self._item_cache.pop(col, None)

except InvalidIndexError:
# GH48729: Seems like you are trying to assign a value to a
# row when only scalar options are permitted
raise InvalidIndexError(
f"You can only assign a scalar value not a {type(value)} "
"with value {value}"
)

def _ensure_valid_index(self, value) -> None:
"""
Ensure that if we don't have an index, that we can create one from the
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexing/test_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,10 @@ def test_at_categorical_integers(self):
for key in [0, 1]:
with pytest.raises(KeyError, match=str(key)):
df.at[key, key]

def test_at_applied_for_rows(self):
# GH#48729 .at should raise InvalidIndexError when assigning rows
df = DataFrame(index=["a"], columns=["col1", "col2"])
new_row = [123, 15]
with pytest.raises(InvalidIndexError, match=str(new_row)):
df.at["a"] = new_row