Skip to content

Commit 32d650d

Browse files
authored
TST: groupby of idxmax/min with mixed types (#40795)
1 parent 918e9f4 commit 32d650d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/frame/test_reductions.py

+22
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,28 @@ def test_idxmax_mixed_dtype(self):
10261026
expected = Series([0, 2, 1, 2], index=[1, 2, 3, 4])
10271027
tm.assert_series_equal(result, expected)
10281028

1029+
@pytest.mark.parametrize(
1030+
"op, expected_value",
1031+
[("idxmax", [0, 4]), ("idxmin", [0, 5])],
1032+
)
1033+
def test_idxmax_idxmin_convert_dtypes(self, op, expected_value):
1034+
# GH 40346
1035+
df = DataFrame(
1036+
{
1037+
"ID": [100, 100, 100, 200, 200, 200],
1038+
"value": [0, 0, 0, 1, 2, 0],
1039+
},
1040+
dtype="Int64",
1041+
)
1042+
df = df.groupby("ID")
1043+
1044+
result = getattr(df, op)()
1045+
expected = DataFrame(
1046+
{"value": expected_value},
1047+
index=Index([100, 200], dtype="object", name="ID"),
1048+
)
1049+
tm.assert_frame_equal(result, expected)
1050+
10291051
def test_idxmax_dt64_multicolumn_axis1(self):
10301052
dti = date_range("2016-01-01", periods=3)
10311053
df = DataFrame({3: dti, 4: dti[::-1]})

0 commit comments

Comments
 (0)