From e4039ce1056e93b8b0e83ffdaeefd3be2b86838e Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 11 Apr 2018 00:26:27 -0700 Subject: [PATCH 1/3] Added test for issue --- pandas/tests/groupby/test_transform.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/groupby/test_transform.py b/pandas/tests/groupby/test_transform.py index 23326d1b105fe..390b99d0fab1c 100644 --- a/pandas/tests/groupby/test_transform.py +++ b/pandas/tests/groupby/test_transform.py @@ -723,3 +723,15 @@ def get_result(grp_obj): exp = DataFrame({'vals': exp_vals * 2}) result = get_result(grp) tm.assert_frame_equal(result, exp) + + @pytest.mark.parametrize("func", [np.any, np.all]) + def test_any_all_np_func(self, func): + # GH 20653 + df = pd.DataFrame([['foo', True], + [np.nan, True], + ['foo', True]], columns=['key', 'val']) + + exp = pd.Series([True, np.nan, True], name='val') + + res = df.groupby('key')['val'].transform(func) + tm.assert_series_equal(res, exp) From 48fd5ea41c2af7da5317538cf2d252a8ff1cd97a Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 11 Apr 2018 00:39:06 -0700 Subject: [PATCH 2/3] Added any/all to _cython_table --- pandas/core/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/base.py b/pandas/core/base.py index 8907e9144b60e..0d55fa8b97aae 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -188,6 +188,8 @@ class SelectionMixin(object): builtins.sum: 'sum', builtins.max: 'max', builtins.min: 'min', + np.all: 'all', + np.any: 'any', np.sum: 'sum', np.mean: 'mean', np.prod: 'prod', From bb845facafe9fdf4164f6edeb89e3e24fb93b0a5 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 11 Apr 2018 00:43:58 -0700 Subject: [PATCH 3/3] Whatsnew Update --- doc/source/whatsnew/v0.23.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index daa7f937cca9d..94b4f6f3ab72f 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1130,6 +1130,7 @@ Groupby/Resample/Rolling - Fixed a performance regression for ``GroupBy.nth`` and ``GroupBy.last`` with some object columns (:issue:`19283`) - Bug in :func:`DataFrameGroupBy.cumsum` and :func:`DataFrameGroupBy.cumprod` when ``skipna`` was passed (:issue:`19806`) - Bug in :func:`Dataframe.resample` that dropped timezone information (:issue:`13238`) +- Bug in :func:`DataFrame.groupby` where transformations using ``np.all`` and ``np.any`` were raising a ``ValueError`` (:issue:`20653`) Sparse ^^^^^^