Skip to content
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

Fixed metadata propagation in Dataframe.idxmax and Dataframe.idxmin #… #47821

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
"""
Expand Down
14 changes: 3 additions & 11 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down