Skip to content

Commit 0673d7f

Browse files
committed
ENH: Add warning when colname collides with methods
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 #5904.
1 parent 379cf86 commit 0673d7f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pandas/core/generic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,10 @@ def _slice(self, slobj, axis=0, kind=None):
17871787
return result
17881788

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

0 commit comments

Comments
 (0)