Skip to content

Commit 15ebdbc

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 61eca9d commit 15ebdbc

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

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

0 commit comments

Comments
 (0)