From ada1c9ef298b47fe26ad916717d7e4f2ef9bf1c4 Mon Sep 17 00:00:00 2001 From: Vinicius Akira Imaizumi Date: Thu, 29 Dec 2022 20:34:39 +0100 Subject: [PATCH 1/3] TST: GH50347 create test for groupby sum of boolean values. --- pandas/tests/groupby/test_groupby.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index b2fc60b76fdf6..27c02daa09418 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2828,3 +2828,11 @@ def test_groupby_index_name_in_index_content(val_in, index, val_out): result = series.to_frame().groupby("blah").sum() expected = expected.to_frame() tm.assert_frame_equal(result, expected) + + +def test_sum_of_booleans(): + # GH 50347 + n = 32 + df = DataFrame({"groupby_col": 1, "bool": [True] * n}) + df["bool"] = df["bool"].eq(True) + assert df.groupby("groupby_col").sum().iloc[0, 0] == 32 From 23e1a6ec1ed26380704d75d7b58a372e073c041d Mon Sep 17 00:00:00 2001 From: Vinicius Akira Imaizumi Date: Fri, 30 Dec 2022 00:38:44 +0100 Subject: [PATCH 2/3] Compare whole object and parametrize with n in [1, 10, 100, 1000] --- pandas/tests/groupby/test_groupby.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 27c02daa09418..fa7ab6cf1e65b 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2830,9 +2830,11 @@ def test_groupby_index_name_in_index_content(val_in, index, val_out): tm.assert_frame_equal(result, expected) -def test_sum_of_booleans(): +@pytest.mark.parametrize("n", [1, 10, 100, 1000]) +def test_sum_of_booleans(n): # GH 50347 - n = 32 df = DataFrame({"groupby_col": 1, "bool": [True] * n}) df["bool"] = df["bool"].eq(True) - assert df.groupby("groupby_col").sum().iloc[0, 0] == 32 + result = df.groupby("groupby_col").sum() + expected = DataFrame({"bool": [n]}, index=Index([1], name="groupby_col")) + tm.assert_frame_equal(result, expected) From 5375996f1ac36b5891703f71b9034dcf85df88ed Mon Sep 17 00:00:00 2001 From: Vinicius Akira Imaizumi Date: Fri, 30 Dec 2022 12:33:42 +0100 Subject: [PATCH 3/3] Added n = 32 for groupby test_sum_of_booleans --- pandas/tests/groupby/test_groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index fa7ab6cf1e65b..a59c2853fa50b 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2830,7 +2830,7 @@ def test_groupby_index_name_in_index_content(val_in, index, val_out): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("n", [1, 10, 100, 1000]) +@pytest.mark.parametrize("n", [1, 10, 32, 100, 1000]) def test_sum_of_booleans(n): # GH 50347 df = DataFrame({"groupby_col": 1, "bool": [True] * n})