Skip to content

TST: Added a test for groupby.prod #56384

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

Merged
merged 8 commits into from
Dec 9, 2023
Merged
Changes from 5 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
24 changes: 24 additions & 0 deletions pandas/tests/groupby/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,3 +1057,27 @@ def test_regression_allowlist_methods(op, axis, skipna, sort):
if sort:
expected = expected.sort_index(axis=axis)
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("multiplier", range(90))
def test_prod_groupby_consistency_values(multiplier):
data = [
[1, 10],
[1, 21],
[1, 32],
[1, 43],
[1, 54],
[1, 67],
[1, 78],
[1, 89],
[1, 5],
[1, 17],
[1, 37],
[1, 47],
[1, 99],
[1, multiplier],
]
df = DataFrame(data, columns=["A", "B"])
df_prod = DataFrame([df.prod()], columns=df.columns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you hardcode this instead (assuming the parametrization will be removed)

Copy link
Member

@rhshadrach rhshadrach Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "hardcode", I mean something like expected = DataFrame([[12345], [6789]], columns["B"]). In other words, don't use df.prod().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhshadrach Sorry for the misunderstanding. I have now updated the code based on your explanation. Could you please take a look and let me know if this is now correct, or if there are any further modifications needed? Thanks for your kind assistance.

df_groupby_prod = df.groupby(["A"]).prod().reset_index()
tm.assert_frame_equal(df_prod, df_groupby_prod)