Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: revert collision warning #17298

Merged
merged 5 commits into from Sep 7, 2017

Conversation

deniederhut
Copy link
Contributor

Reverts work in #16951 that warns when creating a column whose name collides with a method.

@gfyoung gfyoung added Compat pandas objects compatability with Numpy or Python functions Error Reporting Incorrect or improved errors from pandas labels Aug 21, 2017
@jorisvandenbossche jorisvandenbossche removed the Compat pandas objects compatability with Numpy or Python functions label Aug 21, 2017
@jorisvandenbossche
Copy link
Member

Thanks a lot!

One related thing is that it would be nice if one actually gets a warning when you try to overwrite a built-in so not assigning a column like df['mean'] which does not override the .mean() method, but with df.mean = [...].

Example with master:

In [1]: df = pd.DataFrame({'test': [1, 2, 3, 4]})

In [2]: df
Out[2]: 
   test
0     1
1     2
2     3
3     4

In [3]: df.mean = [2, 3, 4, 5]

In [4]: df
Out[4]: 
   test
0     1
1     2
2     3
3     4

In [5]: df.mean()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-4bf1ee5cd33c> in <module>()
----> 1 df.mean()

TypeError: 'list' object is not callable

(but didn't look in detail, so not sure if this is actually possible / easy to do)

@jorisvandenbossche jorisvandenbossche added this to the 0.21.0 milestone Aug 21, 2017
@jorisvandenbossche
Copy link
Member

@deniederhut Can you also take a look at this comment on the warning message? #16951 (comment)

@deniederhut
Copy link
Contributor Author

Hi @jorisvandenbossche! I've updated the warning message to:

Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access

I have mixed feelings about warning on df.mean = [...]. I think people might find it to be surprising, because the general pattern in Python is to permit overwriting of public methods. If this is something that the maintainers would really like to see, I can start looking into an implementation.

@codecov
Copy link

codecov bot commented Aug 21, 2017

Codecov Report

Merging #17298 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17298      +/-   ##
==========================================
- Coverage   91.03%   91.01%   -0.02%     
==========================================
  Files         162      162              
  Lines       49567    49565       -2     
==========================================
- Hits        45123    45112      -11     
- Misses       4444     4453       +9
Flag Coverage Δ
#multiple 88.79% <ø> (-0.01%) ⬇️
#single 40.24% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 92.02% <ø> (-0.01%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58d8729...72a479d. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 21, 2017

Codecov Report

Merging #17298 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17298      +/-   ##
==========================================
- Coverage   91.15%   91.14%   -0.02%     
==========================================
  Files         163      163              
  Lines       49591    49589       -2     
==========================================
- Hits        45207    45196      -11     
- Misses       4384     4393       +9
Flag Coverage Δ
#multiple 88.92% <100%> (-0.01%) ⬇️
#single 40.25% <0%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 91.98% <100%> (-0.01%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 20fee85...422a701. Read the comment docs.

@deniederhut
Copy link
Contributor Author

@jorisvandenbossche I've fixed the name that circle-ci was tripping on. Is this good to go?

@jreback
Copy link
Contributor

jreback commented Sep 6, 2017

@deniederhut can you rebase this just to make sure no changes; ping on green. lgtm.

Closes pandas-dev#17268 and reverts work from pandas-dev#16951 which warns users when creating
a column whose name matches one of the methods defined on ndframes (e.g.
'sum' or 'mean'). The warning was deemed to be too much of a hindrance to
the common use case of generating dataframes of summary statistics.
@jreback jreback merged commit 24b440e into pandas-dev:master Sep 7, 2017
@jreback
Copy link
Contributor

jreback commented Sep 7, 2017

thanks!

@deniederhut
Copy link
Contributor Author

😄

jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Sep 10, 2017
alanbato pushed a commit to alanbato/pandas that referenced this pull request Nov 10, 2017
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove warning when setting columns that conflict with built-in methods
4 participants