Skip to content

Commit 881e434

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 465c59f commit 881e434

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
@@ -3356,6 +3356,10 @@ def __setattr__(self, name, value):
33563356
else:
33573357
object.__setattr__(self, name, value)
33583358
except (AttributeError, TypeError):
3359+
if (self.ndim > 1) and (is_list_like(value)):
3360+
warnings.warn("Pandas doesn't allow Series to be assigned "
3361+
"into nonexistent columns - see "
3362+
"https://pandas.pydata.org/pandas-docs/stable""/indexing.html#attribute-access")
33593363
object.__setattr__(self, name, value)
33603364

33613365
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)