Skip to content

BUG: Fix groupby methods to include *args and **kwds if applicable. #8758

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

Merged
merged 1 commit into from
Nov 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.15.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Experimental

Bug Fixes
~~~~~~~~~
- Bug in ``groupby`` signatures that didn't include *args or **kwargs (:issue:`8733`).
23 changes: 23 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -4415,6 +4415,26 @@ def test_regression_whitelist_methods(self) :
expected = getattr(frame,op)(level=level,axis=axis)
assert_frame_equal(result, expected)

def test_regression_kwargs_whitelist_methods(self):
# GH8733

index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
['one', 'two', 'three']],
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
names=['first', 'second'])
raw_frame = DataFrame(np.random.randn(10, 3), index=index,
columns=Index(['A', 'B', 'C'], name='exp'))

grouped = raw_frame.groupby(level=0, axis=1)
grouped.all(test_kwargs='Test kwargs')
grouped.any(test_kwargs='Test kwargs')
grouped.cumcount(test_kwargs='Test kwargs')
grouped.mad(test_kwargs='Test kwargs')
grouped.cummin(test_kwargs='Test kwargs')
grouped.skew(test_kwargs='Test kwargs')
grouped.cumprod(test_kwargs='Test kwargs')

def test_groupby_blacklist(self):
from string import ascii_lowercase
letters = np.array(list(ascii_lowercase))
Expand Down Expand Up @@ -4460,6 +4480,9 @@ def test_series_groupby_plotting_nominally_works(self):
tm.close()
height.groupby(gender).hist()
tm.close()
#Regression test for GH8733
height.groupby(gender).plot(alpha=0.5)
tm.close()

def test_plotting_with_float_index_works(self):
_skip_if_mpl_not_installed()
Expand Down
4 changes: 4 additions & 0 deletions pandas/util/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,9 @@ def make_signature(func) :
args = []
for i, (var, default) in enumerate(zip(spec.args, defaults)) :
args.append(var if default=='' else var+'='+repr(default))
if spec.varargs:
Copy link
Contributor

Choose a reason for hiding this comment

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

their is a test section for these, can you see if you can add a couple of non-plotting tests (e.g. one that has args, the other kwargs)

namely ones that go thru this machinery

args.append('*' + spec.varargs)
if spec.keywords:
args.append('**' + spec.keywords)
return args, spec.args