Skip to content

Commit 24b440e

Browse files
deniederhutjreback
authored andcommitted
BUG: revert collision warning (#17298)
1 parent 20fee85 commit 24b440e

File tree

5 files changed

+7
-49
lines changed

5 files changed

+7
-49
lines changed

doc/source/indexing.rst

-15
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,6 @@ new column. In 0.21.0 and later, this will raise a ``UserWarning``:
269269
1 2.0
270270
2 3.0
271271
272-
Similarly, it is possible to create a column with a name which collides with one of Pandas's
273-
built-in methods or attributes, which can cause confusion later when attempting to access
274-
that column as an attribute. This behavior now warns:
275-
276-
.. code-block:: ipython
277-
278-
In[4]: df['sum'] = [5., 7., 9.]
279-
UserWarning: Column name 'sum' collides with a built-in method, which will cause unexpected attribute behavior
280-
In[5]: df.sum
281-
Out[5]:
282-
<bound method DataFrame.sum of one sum
283-
0 1.0 5.0
284-
1 2.0 7.0
285-
2 3.0 9.0>
286-
287272
Slicing ranges
288273
--------------
289274

doc/source/whatsnew/v0.21.0.txt

+3-21
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Improved warnings when attempting to create columns
6767
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6868

6969
New users are often flummoxed by the relationship between column operations and attribute
70-
access on ``DataFrame`` instances (:issue:`5904` & :issue:`7175`). Two specific instances
71-
of this confusion include attempting to create a new column by setting into an attribute:
70+
access on ``DataFrame`` instances (:issue:`7175`). One specific instance
71+
of this confusion is attempting to create a new column by setting into an attribute:
7272

7373
.. code-block:: ipython
7474

@@ -86,25 +86,7 @@ This does not raise any obvious exceptions, but also does not create a new colum
8686
1 2.0
8787
2 3.0
8888

89-
The second source of confusion is creating a column whose name collides with a method or
90-
attribute already in the instance namespace:
91-
92-
.. code-block:: ipython
93-
94-
In[4]: df['sum'] = [5., 7., 9.]
95-
96-
This does not permit that column to be accessed as an attribute:
97-
98-
.. code-block:: ipython
99-
100-
In[5]: df.sum
101-
Out[5]:
102-
<bound method DataFrame.sum of one sum
103-
0 1.0 5.0
104-
1 2.0 7.0
105-
2 3.0 9.0>
106-
107-
Both of these now raise a ``UserWarning`` about the potential for unexpected behavior. See :ref:`Attribute Access <indexing.attribute_access>`.
89+
Setting a list-like data structure into a new attribute now raise a ``UserWarning`` about the potential for unexpected behavior. See :ref:`Attribute Access <indexing.attribute_access>`.
10890

10991
.. _whatsnew_0210.enhancements.other:
11092

pandas/core/generic.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1905,10 +1905,6 @@ def _slice(self, slobj, axis=0, kind=None):
19051905
return result
19061906

19071907
def _set_item(self, key, value):
1908-
if isinstance(key, str) and callable(getattr(self, key, None)):
1909-
warnings.warn("Column name '{key}' collides with a built-in "
1910-
"method, which will cause unexpected attribute "
1911-
"behavior".format(key=key), stacklevel=3)
19121908
self._data.set(key, value)
19131909
self._clear_item_cache()
19141910

@@ -3441,8 +3437,8 @@ def __setattr__(self, name, value):
34413437
object.__setattr__(self, name, value)
34423438
except (AttributeError, TypeError):
34433439
if isinstance(self, ABCDataFrame) and (is_list_like(value)):
3444-
warnings.warn("Pandas doesn't allow Series to be assigned "
3445-
"into nonexistent columns - see "
3440+
warnings.warn("Pandas doesn't allow columns to be "
3441+
"created via a new attribute name - see "
34463442
"https://pandas.pydata.org/pandas-docs/"
34473443
"stable/indexing.html#attribute-access",
34483444
stacklevel=2)

pandas/tests/dtypes/test_generic.py

-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def test_abc_types(self):
4848

4949

5050
def test_setattr_warnings():
51-
# GH5904 - Suggestion: Warning for DataFrame colname-methodname clash
5251
# GH7175 - GOTCHA: You can't use dot notation to add a column...
5352
d = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
5453
'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
@@ -78,7 +77,3 @@ def test_setattr_warnings():
7877
# warn when setting column to nonexistent name
7978
df.four = df.two + 2
8079
assert df.four.sum() > df.two.sum()
81-
82-
with tm.assert_produces_warning(UserWarning):
83-
# warn when column has same name as method
84-
df['sum'] = df.two

pandas/tests/io/test_pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ def check(obj, comparator):
20112011
df['string'] = 'foo'
20122012
df['float322'] = 1.
20132013
df['float322'] = df['float322'].astype('float32')
2014-
df['boolean'] = df['float322'] > 0
2014+
df['bool'] = df['float322'] > 0
20152015
df['time1'] = Timestamp('20130101')
20162016
df['time2'] = Timestamp('20130102')
20172017
check(df, tm.assert_frame_equal)
@@ -2141,7 +2141,7 @@ def test_table_values_dtypes_roundtrip(self):
21412141
df1['string'] = 'foo'
21422142
df1['float322'] = 1.
21432143
df1['float322'] = df1['float322'].astype('float32')
2144-
df1['boolean'] = df1['float32'] > 0
2144+
df1['bool'] = df1['float32'] > 0
21452145
df1['time1'] = Timestamp('20130101')
21462146
df1['time2'] = Timestamp('20130102')
21472147

0 commit comments

Comments
 (0)