Skip to content

Commit 3393846

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 80e40f8 commit 3393846

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
@@ -3237,6 +3237,10 @@ def __setattr__(self, name, value):
32373237
else:
32383238
object.__setattr__(self, name, value)
32393239
except (AttributeError, TypeError):
3240+
if (self.ndim > 1) and (is_list_like(value)):
3241+
warnings.warn("Pandas doesn't allow Series to be assigned "
3242+
"into nonexistent columns - see "
3243+
"https://pandas.pydata.org/pandas-docs/stable""/indexing.html#attribute-access")
32403244
object.__setattr__(self, name, value)
32413245

32423246
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)