Skip to content

test case for transform with fillna #27905 #27974

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

Closed
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
29 changes: 29 additions & 0 deletions pandas/tests/groupby/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,3 +1074,32 @@ def test_transform_lambda_with_datetimetz():
name="time",
)
assert_series_equal(result, expected)


@pytest.mark.parametrize(
"inputDF, expectedDF",
Copy link
Member

Choose a reason for hiding this comment

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

inputDF -> input_df
expectedDF -> expected_df

are there other dtypes we should be testing?

[
(
DataFrame(
{
"A": [121, 121, 121, 121, 231, 231, 676],
"B": [1, 2, np.nan, 3, 3, np.nan, 4],
}
),
1,
),
(
DataFrame(
{
"A": [121, 121, 121, 121, 231, 231, 676],
"B": [1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0],
}
),
1,
),
],
)
def test_groupby_transform_fillna(inputDF, expectedDF):
# GH 27905 - Test fillna in groupby.transform
input1 = inputDF.groupby("A").transform(lambda x: x.fillna(x.mean()))
Copy link
Contributor

Choose a reason for hiding this comment

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

use the forms

result =
tm.assert_frame_equal(result, expected)

assert all(input1 == expectedDF)