Skip to content

Commit e8d5e6e

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 6085d92 commit e8d5e6e

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

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

0 commit comments

Comments
 (0)