We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 918e9f4 commit 32d650dCopy full SHA for 32d650d
pandas/tests/frame/test_reductions.py
@@ -1026,6 +1026,28 @@ def test_idxmax_mixed_dtype(self):
1026
expected = Series([0, 2, 1, 2], index=[1, 2, 3, 4])
1027
tm.assert_series_equal(result, expected)
1028
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
1051
def test_idxmax_dt64_multicolumn_axis1(self):
1052
dti = date_range("2016-01-01", periods=3)
1053
df = DataFrame({3: dti, 4: dti[::-1]})
0 commit comments