Skip to content

Commit

Permalink
Fixed metadata propagation in Dataframe.idxmax and Dataframe.idxmin #… (
Browse files Browse the repository at this point in the history
#47821)

* Fixed metadata propagation in Dataframe.idxmax and Dataframe.idxmin #28283

* fixing PEP 8 issues

* removing unnecessary pytest.param()

* removing unnecessary pytest.param
  • Loading branch information
SomtochiUmeh committed Jul 25, 2022
1 parent e6f1537 commit b0a51fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
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

0 comments on commit b0a51fe

Please sign in to comment.