Skip to content

Commit 94c91af

Browse files
committed
Merge pull request #8758 from dstephens99/issue8733
BUG: Fix groupby methods to include *args and **kwds if applicable.
2 parents 66a0a74 + d6d5542 commit 94c91af

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

doc/source/whatsnew/v0.15.2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ Experimental
4242

4343
Bug Fixes
4444
~~~~~~~~~
45+
- Bug in ``groupby`` signatures that didn't include *args or **kwargs (:issue:`8733`).

pandas/tests/test_groupby.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,6 +4415,26 @@ def test_regression_whitelist_methods(self) :
44154415
expected = getattr(frame,op)(level=level,axis=axis)
44164416
assert_frame_equal(result, expected)
44174417

4418+
def test_regression_kwargs_whitelist_methods(self):
4419+
# GH8733
4420+
4421+
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
4422+
['one', 'two', 'three']],
4423+
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
4424+
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
4425+
names=['first', 'second'])
4426+
raw_frame = DataFrame(np.random.randn(10, 3), index=index,
4427+
columns=Index(['A', 'B', 'C'], name='exp'))
4428+
4429+
grouped = raw_frame.groupby(level=0, axis=1)
4430+
grouped.all(test_kwargs='Test kwargs')
4431+
grouped.any(test_kwargs='Test kwargs')
4432+
grouped.cumcount(test_kwargs='Test kwargs')
4433+
grouped.mad(test_kwargs='Test kwargs')
4434+
grouped.cummin(test_kwargs='Test kwargs')
4435+
grouped.skew(test_kwargs='Test kwargs')
4436+
grouped.cumprod(test_kwargs='Test kwargs')
4437+
44184438
def test_groupby_blacklist(self):
44194439
from string import ascii_lowercase
44204440
letters = np.array(list(ascii_lowercase))
@@ -4460,6 +4480,9 @@ def test_series_groupby_plotting_nominally_works(self):
44604480
tm.close()
44614481
height.groupby(gender).hist()
44624482
tm.close()
4483+
#Regression test for GH8733
4484+
height.groupby(gender).plot(alpha=0.5)
4485+
tm.close()
44634486

44644487
def test_plotting_with_float_index_works(self):
44654488
_skip_if_mpl_not_installed()

pandas/util/decorators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,9 @@ def make_signature(func) :
282282
args = []
283283
for i, (var, default) in enumerate(zip(spec.args, defaults)) :
284284
args.append(var if default=='' else var+'='+repr(default))
285+
if spec.varargs:
286+
args.append('*' + spec.varargs)
287+
if spec.keywords:
288+
args.append('**' + spec.keywords)
285289
return args, spec.args
286290

0 commit comments

Comments
 (0)