From f27353c5c2cd322de312a97e19b239f54cbd7094 Mon Sep 17 00:00:00 2001 From: Jason Jia Date: Sat, 11 Jun 2022 23:21:23 -0500 Subject: [PATCH 1/7] DOC: added example of valid input dict in dfgroupby.aggregate --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index c294082edce71..bd3311319090f 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -518,7 +518,7 @@ class providing the base-class of operations. - function - string function name - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` - - dict of axis labels -> functions, function names or list of such. + - dict of axis labels -> functions, function names or list of such, e.g. ``{{'col1': 'min', 'col2': list}}``. Can also accept a Numba JIT function with ``engine='numba'`` specified. Only passing a single function is supported From 60659365c2e67089166795ca0b5f45b361d16617 Mon Sep 17 00:00:00 2001 From: Jason Jia Date: Sat, 11 Jun 2022 23:49:46 -0500 Subject: [PATCH 2/7] Updated line spacing to pass flake8 test --- pandas/core/groupby/groupby.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index bd3311319090f..04b8debfd561d 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -518,7 +518,8 @@ class providing the base-class of operations. - function - string function name - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` - - dict of axis labels -> functions, function names or list of such, e.g. ``{{'col1': 'min', 'col2': list}}``. + - dict of axis labels -> functions, function names or list of such, + e.g. ``{{'col1': 'min', 'col2': list}}``. Can also accept a Numba JIT function with ``engine='numba'`` specified. Only passing a single function is supported From ce333612241560acfa36bfb40d0ba582d8d4fd7e Mon Sep 17 00:00:00 2001 From: Jason Jia Date: Sat, 11 Jun 2022 23:53:05 -0500 Subject: [PATCH 3/7] Removed trailing whitespace --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 04b8debfd561d..16b203871135a 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -518,7 +518,7 @@ class providing the base-class of operations. - function - string function name - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` - - dict of axis labels -> functions, function names or list of such, + - dict of axis labels -> functions, function names or list of such, e.g. ``{{'col1': 'min', 'col2': list}}``. Can also accept a Numba JIT function with From ff1f2d84bb6ddcbaca6f1e210ae52ad44e657746 Mon Sep 17 00:00:00 2001 From: Jason Jia Date: Sun, 12 Jun 2022 05:46:15 -0500 Subject: [PATCH 4/7] retrying tests --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 16b203871135a..6d5e3bf5fb727 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -519,7 +519,7 @@ class providing the base-class of operations. - string function name - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` - dict of axis labels -> functions, function names or list of such, - e.g. ``{{'col1': 'min', 'col2': list}}``. + e.g. ``{{'col1': 'min', 'col2': list}}`` Can also accept a Numba JIT function with ``engine='numba'`` specified. Only passing a single function is supported From 225d5580946dca04d1db911394b3ce4f024c1fb3 Mon Sep 17 00:00:00 2001 From: Jason Jia Date: Sun, 12 Jun 2022 17:00:39 -0500 Subject: [PATCH 5/7] Rerun tests --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 6d5e3bf5fb727..16b203871135a 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -519,7 +519,7 @@ class providing the base-class of operations. - string function name - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` - dict of axis labels -> functions, function names or list of such, - e.g. ``{{'col1': 'min', 'col2': list}}`` + e.g. ``{{'col1': 'min', 'col2': list}}``. Can also accept a Numba JIT function with ``engine='numba'`` specified. Only passing a single function is supported From fe5073ae83e57ec84d0d92ca3ea7fe75dfc0dac2 Mon Sep 17 00:00:00 2001 From: Jason Jia Date: Mon, 13 Jun 2022 17:33:28 -0500 Subject: [PATCH 6/7] added user-defined function to examples --- pandas/core/groupby/generic.py | 8 ++++++++ pandas/core/groupby/groupby.py | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 38b93c6be60f8..fa4aa6d63dff4 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -814,6 +814,14 @@ class DataFrameGroupBy(GroupBy[DataFrame]): 1 1 2 2 3 4 + User-defined function for aggregation + + >>> df.groupby('A').agg(lambda x: sum(x) + 2) + B C + A + 1 5 2.590715 + 2 9 2.704907 + Different aggregations per column >>> df.groupby('A').agg({'B': ['min', 'max'], 'C': 'sum'}) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 6d5e3bf5fb727..c294082edce71 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -518,8 +518,7 @@ class providing the base-class of operations. - function - string function name - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` - - dict of axis labels -> functions, function names or list of such, - e.g. ``{{'col1': 'min', 'col2': list}}`` + - dict of axis labels -> functions, function names or list of such. Can also accept a Numba JIT function with ``engine='numba'`` specified. Only passing a single function is supported From 544e6ebb8e474dc5ca8caae3cd58592156994939 Mon Sep 17 00:00:00 2001 From: Jason Jia Date: Mon, 13 Jun 2022 17:48:32 -0500 Subject: [PATCH 7/7] Update generic.py --- pandas/core/groupby/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index fa4aa6d63dff4..b4aea4240e458 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -818,7 +818,7 @@ class DataFrameGroupBy(GroupBy[DataFrame]): >>> df.groupby('A').agg(lambda x: sum(x) + 2) B C - A + A 1 5 2.590715 2 9 2.704907