Skip to content

BUG: pass *args and **kwargs for wrapped methods in Groupby (#14107) #14109

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 5 commits into from
Closed
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
4 changes: 4 additions & 0 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,10 @@ def %(name)s(self) :
# GroupBy._make_wrapper won't know whether
# we passed in an axis parameter.
args_by_name = ['{0}={0}'.format(arg) for arg in args[1:]]
# include *args or **kwargs if the original signature takes them
args_by_name.extend(
declitem for declitem in decl if declitem.startswith('*')
)
params = {'name': name,
'doc': doc,
'sig': ','.join(decl),
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -5947,6 +5947,18 @@ def test_groupby_blacklist(self):
with tm.assertRaisesRegexp(AttributeError, msg):
getattr(gb, bl)

def test_groupby_varargs(self):
# GH 14107
# we want to make sure **kwargs arguments are passed on correctly
# in this example, `take` uses **kwargs to pass on the 'mode' argument
# it should fail both when used directly and when via grouped object
s = Series([1, 2, 3])
g = s.groupby(int)
with tm.assertRaises(ValueError):
s.take([0], mode='INVALID_MODE_SHOULD_RAISE')
with tm.assertRaises(ValueError):
g.take([0], mode='INVALID_MODE_SHOULD_RAISE')

def test_tab_completion(self):
grp = self.mframe.groupby(level='second')
results = set([v for v in dir(grp) if not v.startswith('_')])
Expand Down
1 change: 0 additions & 1 deletion pandas/tseries/tests/test_tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ def test_parsers(self):
'00-Q4': datetime.datetime(2000, 10, 1),
'4Q-2000': datetime.datetime(2000, 10, 1),
'4Q-00': datetime.datetime(2000, 10, 1),
'2000q4': datetime.datetime(2000, 10, 1),
'00q4': datetime.datetime(2000, 10, 1),
'2005': datetime.datetime(2005, 1, 1),
'2005-11': datetime.datetime(2005, 11, 1),
Expand Down