Skip to content

Commit c1ea62c

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 pandas-dev#5904.
1 parent 43ffc7a commit c1ea62c

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
@@ -1824,6 +1824,10 @@ def _slice(self, slobj, axis=0, kind=None):
18241824
return result
18251825

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

0 commit comments

Comments
 (0)