Skip to content

TST: groupby of idxmax/min with mixed types #40795

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 10 commits into from
Apr 14, 2021
40 changes: 40 additions & 0 deletions pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,46 @@ def test_idxmax_mixed_dtype(self):
expected = Series([0, 2, 1, 2], index=[1, 2, 3, 4])
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize(
"ID, value, expected_index, expected_value",
[([100, 100, 100, 200, 200, 200], [0, 0, 0, 1, 2, 0], [100, 200], [0, 4])],
Copy link
Member

@phofl phofl Apr 7, 2021

Choose a reason for hiding this comment

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

Please parametrize over ecpected values and the applied function only, you will need only one test then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @phofl , will redo and push

)
def test_idxmax_convert_dtypes(self, ID, value, expected_index, expected_value):
df2 = DataFrame(
{
"ID": ID,
"value": value,
}
)
df2 = df2.convert_dtypes()

result = df2.groupby("ID").idxmax()
expected = DataFrame(
{"value": expected_value},
index=Index(expected_index, dtype="object", name="ID"),
)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"ID, value, expected_index, expected_value",
[([100, 100, 100, 200, 200, 200], [0, 0, 0, 1, 2, 0], [100, 200], [0, 5])],
)
def test_idxmin_convert_dtypes(self, ID, value, expected_index, expected_value):
df2 = DataFrame(
{
"ID": ID,
"value": value,
}
)
df2 = df2.convert_dtypes()

result = df2.groupby("ID").idxmin()
expected = DataFrame(
{"value": expected_value},
index=Index(expected_index, dtype="object", name="ID"),
)
tm.assert_frame_equal(result, expected)

def test_idxmax_dt64_multicolumn_axis1(self):
dti = date_range("2016-01-01", periods=3)
df = DataFrame({3: dti, 4: dti[::-1]})
Expand Down