Skip to content

Commit

Permalink
ENH: Add warning when colname collides with methods
Browse files Browse the repository at this point in the history
Current behavior does not allow attribute-like access when the column
name of a DataFrame matches the name of a method. This commit adds an
explicit warning about this behavior. Closes pandas-dev#5904.
  • Loading branch information
deniederhut committed Jul 15, 2017
1 parent 379cf86 commit 0673d7f
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 @@ -1787,6 +1787,10 @@ def _slice(self, slobj, axis=0, kind=None):
return result

def _set_item(self, key, value):
if callable(getattr(self, key, None)):
warnings.warn("Pandas doesn't allow attribute-like access to "
"columns whose names collide with methods",
stacklevel=3)
self._data.set(key, value)
self._clear_item_cache()

Expand Down

0 comments on commit 0673d7f

Please sign in to comment.