Skip to content

COMPAT: Fix indent level bug preventing wrapper function rename #14620

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

Closed
wants to merge 9 commits into from

Conversation

matthagy
Copy link

@matthagy matthagy commented Nov 9, 2016

Original code intends to rename the wrapper function f using the provided name, but this isn't happening because code is incorrectly indented an extra level.

Example:
>>> from pandas.core.groupby import GroupBy
>>> GroupBy.sum.__name__
'f'

Should be 'sum'.

@jreback
Copy link
Contributor

jreback commented Nov 9, 2016

can u add some tests for this (and validate all functions names in the whitelist would be great)

@matthagy
Copy link
Author

matthagy commented Nov 9, 2016

@jreback, tried adding a test for all whitelist function names and discovered there are additional places where attribute and method names are inconsistent. Replaced that with a test that only covers the names corresponding to this current bug fix. If you think it makes sense to hold off until all whitelist function names are properly handled then I can close this PR for now and open an issue.

@jreback
Copy link
Contributor

jreback commented Nov 9, 2016

just make it 2. tests
1 for good ones
1 for failing ones
then can add a TODO for the failing ones

@matthagy
Copy link
Author

matthagy commented Nov 9, 2016

@jreback, added back failing test, commented out, and marked w/ TODO. Does reuse a an existing test to prevent duplicating whitelists or refactoring them to be class members. Let me know if you had something else in mind.

getattr(type(gb), m)
f = getattr(type(gb), m)
# TODO: Fix inconsistencies between attribute and method names
# self.assertEqual(f.__name__, m)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u made an actual test of things in the whitelist which fail

@matthagy
Copy link
Author

matthagy commented Nov 9, 2016

@jreback, revised test to show things in whitelist that currently fail. Test now also handles all of the other whitelist cases that aren't known issues.

@@ -5986,11 +5986,44 @@ def test_groupby_whitelist(self):
# 'nlargest', 'nsmallest',
])

# TODO: Fix these inconsistencies between attribute and method names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this comment mean?

'dtype',
'unique'
])

for obj, whitelist in zip((df, s), (df_whitelist, s_whitelist)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I mean is create another function where you assert that these are NOT equal (with the sub-list of those that are broken), so that when they are fixed this tests will break (and the list will need to be updated). IOW, create a list like the white-list of the broken ones, have the existing test just skip on them (as you do below), but then create another function that asserts that the broken ones are not equal.

@matthagy
Copy link
Author

@jreback, created the additional test to assert that method __name__ is inconsistent with attribute name for these known issues. Also revised the comment explaining the inconsistencies.

@jreback
Copy link
Contributor

jreback commented Dec 21, 2016

@matthagy can you rebase / update.

sorry got a bit lost in the shuffle.

@codecov-io
Copy link

codecov-io commented Dec 22, 2016

Codecov Report

Merging #14620 into master will decrease coverage by 0.01%.
The diff coverage is 93.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14620      +/-   ##
==========================================
- Coverage   90.99%   90.98%   -0.02%     
==========================================
  Files         143      143              
  Lines       49420    49403      -17     
==========================================
- Hits        44972    44949      -23     
- Misses       4448     4454       +6
Impacted Files Coverage Δ
pandas/core/groupby.py 95.03% <93.87%> (+0.05%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/types/cast.py 85.31% <0%> (-0.29%) ⬇️
pandas/core/frame.py 97.56% <0%> (-0.11%) ⬇️
pandas/core/base.py 95.48% <0%> (-0.03%) ⬇️
pandas/io/parsers.py 95.51% <0%> (-0.01%) ⬇️
pandas/io/excel.py 79.67% <0%> (ø) ⬆️
pandas/core/missing.py 84.9% <0%> (+0.62%) ⬆️

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 ec84ae3...db3c6e4. Read the comment docs.

@matthagy
Copy link
Author

@jreback, rebased.

@jreback
Copy link
Contributor

jreback commented Feb 1, 2017

can you rebase?

@matthagy
Copy link
Author

matthagy commented Feb 1, 2017

@jreback, rebased.

@jreback
Copy link
Contributor

jreback commented Feb 1, 2017

thanks @matthagy
lgtm. ping on green.

@jreback jreback added this to the 0.20.0 milestone Feb 1, 2017
@jreback
Copy link
Contributor

jreback commented Feb 16, 2017

can you rebase / update

@jreback
Copy link
Contributor

jreback commented Mar 23, 2017

@matthagy can you rebase / ping on green.

@jreback
Copy link
Contributor

jreback commented Mar 27, 2017

@matthagy I pushed a change here to make this also set __qualname__ (we do this already all Series/DataFrame anyhow, so seemed easy to add here.

Can you push a whatsnew note, otherwise this lgtm. I think you had several TODO's in the tests for functions which don't set things properly, can you have a look at those?

@@ -3753,6 +3753,19 @@ def test_groupby_selection_with_methods(self):
assert_frame_equal(g.filter(lambda x: len(x) == 3),
g_exp.filter(lambda x: len(x) == 3))

# The methods returned by these attributes don't have a __name__ attribute
# that matches that attribute.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these here

@@ -3929,6 +3986,12 @@ def test_tab_completion(self):
'ffill', 'bfill', 'pad', 'backfill', 'rolling', 'expanding'])
self.assertEqual(results, expected)

def test_groupby_function_rename(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this test superfluous? (or just a quick test)?

@jreback jreback changed the title Fix indent level bug preventing wrapper function rename COMPAT: Fix indent level bug preventing wrapper function rename Mar 27, 2017
@jreback
Copy link
Contributor

jreback commented Mar 27, 2017

cc @mrocklin

Original code intends to rename the wrapper function f using the provided name, but this isn't happening because code is incorrectly indented an extra level.

Example:
>>> from pandas.core.groupby import GroupBy
>>> GroupBy.sum.__name__
'f'

Should be 'sum'.
@jreback jreback closed this in 2e64614 Mar 28, 2017
mattip pushed a commit to mattip/pandas that referenced this pull request Apr 3, 2017
Original code intends to rename the wrapper function f using the
provided name, but this isn't happening because code is incorrectly
indented an extra level.

from pandas.core.groupby import GroupBy
GroupBy.sum.__name__
Should be 'sum'.

Author: Jeff Reback <[email protected]>
Author: Matt Hagy <[email protected]>
Author: Matt Hagy <[email protected]>

Closes pandas-dev#14620 from matthagy/patch-1 and squashes the following commits:

db3c6e4 [Jeff Reback] clean/reorg tests
205489b [Jeff Reback] doc
8b185b4 [Jeff Reback] PEP
781b9b3 [Jeff Reback] Move _groupby_function inside GroupBy
68013bf [Matt Hagy] Added a test for known inconsistent attribute/method names
3bf8993 [Matt Hagy] Revise attribute/method consistency check to skip known inconsistencies
033e42d [Matt Hagy] Test for consistency of attribute and method names
2a54b77 [Matt Hagy] Test renaming of _groupby_function wrapper function
a492b5a [Matt Hagy] Fix indent level bug preventing wrapper function rename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants