From 14f81a905a89a760eb32656301bee81f0e2e9013 Mon Sep 17 00:00:00 2001 From: TrigonaMinima Date: Fri, 15 Feb 2019 01:45:50 +0530 Subject: [PATCH] 14873: test for groupby.agg coercing booleans --- .../tests/groupby/aggregate/test_aggregate.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index 9de8a08809009..0c2e74c0b735f 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -286,3 +286,20 @@ def test_multi_function_flexible_mix(df): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): result = grouped.aggregate(d) tm.assert_frame_equal(result, expected) + + +def test_groupby_agg_coercing_bools(): + # issue 14873 + dat = pd.DataFrame( + {'a': [1, 1, 2, 2], 'b': [0, 1, 2, 3], 'c': [None, None, 1, 1]}) + gp = dat.groupby('a') + + index = Index([1, 2], name='a') + + result = gp['b'].aggregate(lambda x: (x != 0).all()) + expected = Series([False, True], index=index, name='b') + tm.assert_series_equal(result, expected) + + result = gp['c'].aggregate(lambda x: x.isnull().all()) + expected = Series([True, False], index=index, name='c') + tm.assert_series_equal(result, expected)