Skip to content

Commit aa9fae1

Browse files
Shivam RanaPingviinituutti
Shivam Rana
authored andcommitted
14873: test for groupby.agg coercing booleans (pandas-dev#25327)
1 parent 6beb9b3 commit aa9fae1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/groupby/aggregate/test_aggregate.py

+17
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,20 @@ def test_multi_function_flexible_mix(df):
286286
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
287287
result = grouped.aggregate(d)
288288
tm.assert_frame_equal(result, expected)
289+
290+
291+
def test_groupby_agg_coercing_bools():
292+
# issue 14873
293+
dat = pd.DataFrame(
294+
{'a': [1, 1, 2, 2], 'b': [0, 1, 2, 3], 'c': [None, None, 1, 1]})
295+
gp = dat.groupby('a')
296+
297+
index = Index([1, 2], name='a')
298+
299+
result = gp['b'].aggregate(lambda x: (x != 0).all())
300+
expected = Series([False, True], index=index, name='b')
301+
tm.assert_series_equal(result, expected)
302+
303+
result = gp['c'].aggregate(lambda x: x.isnull().all())
304+
expected = Series([True, False], index=index, name='c')
305+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)