Skip to content

Commit

Permalink
Fixed metadata propagation in Dataframe.idxmax and Dataframe.idxmin p…
Browse files Browse the repository at this point in the history
  • Loading branch information
SomtochiUmeh committed Jul 22, 2022
1 parent bedd8f0 commit 05fdeb3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11010,7 +11010,7 @@ 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))
return data._constructor_sliced(result, index=data._get_agg_axis(axis)).__finalize__(self, method="idxmin")

@doc(_shared_docs["idxmax"], numeric_only_default="False")
def idxmax(
Expand All @@ -11035,7 +11035,7 @@ 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))
return data._constructor_sliced(result, index=data._get_agg_axis(axis)).__finalize__(self, method="idxmax")

def _get_agg_axis(self, axis_num: int) -> Index:
"""
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,10 @@
(pd.DataFrame, frame_data, operator.methodcaller("nunique")),
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("idxmin")),
marks=not_implemented_mark,
(pd.DataFrame, frame_data, operator.methodcaller("idxmin"))
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("idxmax")),
marks=not_implemented_mark,
(pd.DataFrame, frame_data, operator.methodcaller("idxmax"))
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("mode")),
Expand Down

0 comments on commit 05fdeb3

Please sign in to comment.