Skip to content

Commit fe0861e

Browse files
WillAydjreback
authored andcommitted
Np Any/All Transformation Bug (#20655)
1 parent b20fe15 commit fe0861e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ Groupby/Resample/Rolling
11311131
- Fixed a performance regression for ``GroupBy.nth`` and ``GroupBy.last`` with some object columns (:issue:`19283`)
11321132
- Bug in :func:`DataFrameGroupBy.cumsum` and :func:`DataFrameGroupBy.cumprod` when ``skipna`` was passed (:issue:`19806`)
11331133
- Bug in :func:`Dataframe.resample` that dropped timezone information (:issue:`13238`)
1134+
- Bug in :func:`DataFrame.groupby` where transformations using ``np.all`` and ``np.any`` were raising a ``ValueError`` (:issue:`20653`)
11341135

11351136
Sparse
11361137
^^^^^^

pandas/core/base.py

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ class SelectionMixin(object):
188188
builtins.sum: 'sum',
189189
builtins.max: 'max',
190190
builtins.min: 'min',
191+
np.all: 'all',
192+
np.any: 'any',
191193
np.sum: 'sum',
192194
np.mean: 'mean',
193195
np.prod: 'prod',

pandas/tests/groupby/test_transform.py

+12
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,15 @@ def get_result(grp_obj):
723723
exp = DataFrame({'vals': exp_vals * 2})
724724
result = get_result(grp)
725725
tm.assert_frame_equal(result, exp)
726+
727+
@pytest.mark.parametrize("func", [np.any, np.all])
728+
def test_any_all_np_func(self, func):
729+
# GH 20653
730+
df = pd.DataFrame([['foo', True],
731+
[np.nan, True],
732+
['foo', True]], columns=['key', 'val'])
733+
734+
exp = pd.Series([True, np.nan, True], name='val')
735+
736+
res = df.groupby('key')['val'].transform(func)
737+
tm.assert_series_equal(res, exp)

0 commit comments

Comments
 (0)