diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e62f9fa8076d8..47203fbf315e5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11010,7 +11010,8 @@ def idxmin( index = data._get_axis(axis) result = [index[i] if i >= 0 else np.nan for i in indices] - return data._constructor_sliced(result, index=data._get_agg_axis(axis)) + final_result = data._constructor_sliced(result, index=data._get_agg_axis(axis)) + return final_result.__finalize__(self, method="idxmin") @doc(_shared_docs["idxmax"], numeric_only_default="False") def idxmax( @@ -11035,7 +11036,8 @@ def idxmax( index = data._get_axis(axis) result = [index[i] if i >= 0 else np.nan for i in indices] - return data._constructor_sliced(result, index=data._get_agg_axis(axis)) + final_result = data._constructor_sliced(result, index=data._get_agg_axis(axis)) + return final_result.__finalize__(self, method="idxmax") def _get_agg_axis(self, axis_num: int) -> Index: """ diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 6901d415a5ae7..dddab05af7341 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -226,17 +226,9 @@ pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("nunique")), ), - pytest.param( - (pd.DataFrame, frame_data, operator.methodcaller("idxmin")), - marks=not_implemented_mark, - ), - pytest.param( - (pd.DataFrame, frame_data, operator.methodcaller("idxmax")), - marks=not_implemented_mark, - ), - pytest.param( - (pd.DataFrame, frame_data, operator.methodcaller("mode")), - ), + (pd.DataFrame, frame_data, operator.methodcaller("idxmin")), + (pd.DataFrame, frame_data, operator.methodcaller("idxmax")), + (pd.DataFrame, frame_data, operator.methodcaller("mode")), pytest.param( (pd.Series, [0], operator.methodcaller("mode")), marks=not_implemented_mark,