Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14873: test for groupby.agg coercing booleans #25327

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)