Skip to content

Commit 5a2c063

Browse files
committed
ENH: adds warning when setting list-like into attribute
Adds warning in generic setattr logical branch for when attribute does not exist and user is supplying a list-like object. Warning states that Series cannot be assigned into nonexistent columns, and includes a link to stable documentation. Closes pandas-dev#7175.
1 parent dd1852d commit 5a2c063

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pandas/core/generic.py

+4
Original file line numberDiff line numberDiff line change
@@ -3274,6 +3274,10 @@ def __setattr__(self, name, value):
32743274
else:
32753275
object.__setattr__(self, name, value)
32763276
except (AttributeError, TypeError):
3277+
if (self.ndim > 1) and (is_list_like(value)):
3278+
warnings.warn("Pandas doesn't allow Series to be assigned "
3279+
"into nonexistent columns - see "
3280+
"https://pandas.pydata.org/pandas-docs/stable""/indexing.html#attribute-access")
32773281
object.__setattr__(self, name, value)
32783282

32793283
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)