Skip to content

Commit

Permalink
ENH: adds warning when setting list-like into attribute
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deniederhut committed Jul 27, 2017
1 parent 3ab56bd commit 8149d5d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,10 @@ def __setattr__(self, name, value):
else:
object.__setattr__(self, name, value)
except (AttributeError, TypeError):
if (self.ndim > 1) and (is_list_like(value)):
warnings.warn("Pandas doesn't allow Series to be assigned "
"into nonexistent columns - see "
"https://pandas.pydata.org/pandas-docs/stable""/indexing.html#attribute-access")
object.__setattr__(self, name, value)

# ----------------------------------------------------------------------
Expand Down

0 comments on commit 8149d5d

Please sign in to comment.