From 4d6a4d479a7b8b4323562663782160aa43568b9b Mon Sep 17 00:00:00 2001 From: yonatanp Date: Sun, 28 Aug 2016 14:23:01 +0300 Subject: [PATCH 1/5] BUG: pass along *args and **kwargs for wrapped methods in Groupby (#14107) Methods such as 'hist' that take keyword arguments would now be able to be called via a Groupby object and the keyword args would be passed onwards to matplotlib as the user expects. --- pandas/core/groupby.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 9436257b88941..c60540e1b61b6 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -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:]] + # if the original signature takes either *args or **kwargs, pass them along in the same manner + args_by_name.extend( + declitem for declitem in decl if declitem.startswith('*') + ) params = {'name': name, 'doc': doc, 'sig': ','.join(decl), From 026e078efd0f86c369f87537ec81d6ce319833ad Mon Sep 17 00:00:00 2001 From: yonatanp Date: Sun, 28 Aug 2016 17:09:03 +0300 Subject: [PATCH 2/5] CLN: edited comment to match lint rules (too long) --- pandas/core/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index c60540e1b61b6..164c2d5c45198 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -2554,7 +2554,7 @@ 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:]] - # if the original signature takes either *args or **kwargs, pass them along in the same manner + # include *args or **kwargs if the original signature takes them args_by_name.extend( declitem for declitem in decl if declitem.startswith('*') ) From f70ec943d2024e3c2551d33ac55cbf53b77a6dc6 Mon Sep 17 00:00:00 2001 From: yonatanp Date: Fri, 9 Sep 2016 12:56:43 +0300 Subject: [PATCH 3/5] TST: add test to verify groupby varargs proxy (#14107) --- pandas/tests/test_groupby.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 9a82332621933..13139e3747aa1 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -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('_')]) From 5fb6b5a15b9ad61e686f5a777dfbea82c2ed1012 Mon Sep 17 00:00:00 2001 From: yonatanp Date: Fri, 9 Sep 2016 15:04:14 +0300 Subject: [PATCH 4/5] CLN: cleaned test to match PEP8 standards --- pandas/tests/test_groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 13139e3747aa1..c4797d28f2b6c 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -5952,7 +5952,7 @@ def test_groupby_varargs(self): # 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]) + s = Series([1, 2, 3]) g = s.groupby(int) with tm.assertRaises(ValueError): s.take([0], mode='INVALID_MODE_SHOULD_RAISE') From 429509e3ccd80ee6c684e83cf4f50ee15630bfba Mon Sep 17 00:00:00 2001 From: yonatanp Date: Fri, 9 Sep 2016 16:13:11 +0300 Subject: [PATCH 5/5] CLN: removed duplicate line that failed lint test --- pandas/tseries/tests/test_tslib.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tseries/tests/test_tslib.py b/pandas/tseries/tests/test_tslib.py index 22bb3bddbc742..daf6c66df0b13 100644 --- a/pandas/tseries/tests/test_tslib.py +++ b/pandas/tseries/tests/test_tslib.py @@ -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),