Skip to content

DOC: Fix errors in pandas.Series.argmin #32286

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

Merged
merged 18 commits into from
Mar 6, 2020
Merged
Changes from 15 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
46 changes: 19 additions & 27 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,16 +927,19 @@ def max(self, axis=None, skipna=True, *args, **kwargs):
nv.validate_max(args, kwargs)
return nanops.nanmax(self._values, skipna=skipna)

@doc(
op="max", oppose="min", value="largest",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is from black, but I guess you can leave the decorator in a single line, and black will respect it.

)
def argmax(self, axis=None, skipna=True, *args, **kwargs):
"""
Return int position of the largest value in the Series.
Return int position of the {value} value in the Series.

If the maximum is achieved in multiple locations,
If the {op}imum is achieved in multiple locations,
the first row position is returned.

Parameters
----------
axis : {None}
axis : {{None}}
Dummy argument for consistency with Series.
skipna : bool, default True
Exclude NA/null values when showing the result.
Expand All @@ -946,21 +949,22 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):
Returns
-------
int
Row position of the maximum values.
Row position of the {op}imum value.

See Also
--------
numpy.ndarray.argmax : Equivalent method for numpy arrays.
Series.argmin : Similar method, but returning the minimum.
Series.argmax : Return position of the maximum value.
Series.argmin : Return position of the minimum value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not finally using oppose. I think you can replace those two lines by this, and we don't need to repeat the same page in this case. Or you can simply remove the oppose parameter of doc otherwise.

Suggested change
Series.argmin : Return position of the minimum value.
Series.arg{oppose} : Return position of the {oppose}imum value.

numpy.ndarray.arg{op} : Equivalent method for numpy arrays.
Series.idxmax : Return index label of the maximum values.
Series.idxmin : Return index label of the minimum values.

Examples
--------
Consider dataset containing cereal calories

>>> s = pd.Series({'Corn Flakes': 100.0, 'Almond Delight': 110.0,
... 'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0})
>>> s = pd.Series({{'Corn Flakes': 100.0, 'Almond Delight': 110.0,
... 'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0}})
>>> s
Corn Flakes 100.0
Almond Delight 110.0
Expand All @@ -970,8 +974,11 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):

>>> s.argmax()
2
>>> s.argmin()
0

The maximum cereal calories is in the third element,
The maximum cereal calories is the third element and
the minimum cereal calories is the first element,
since series is zero-indexed.
"""
nv.validate_minmax_axis(axis)
Expand Down Expand Up @@ -1019,25 +1026,10 @@ def min(self, axis=None, skipna=True, *args, **kwargs):
nv.validate_min(args, kwargs)
return nanops.nanmin(self._values, skipna=skipna)

@doc(
argmax, op="min", oppose="max", value="smallest",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as before about being a one-liner.

)
def argmin(self, axis=None, skipna=True, *args, **kwargs):
"""
Return a ndarray of the minimum argument indexer.

Parameters
----------
axis : {None}
Dummy argument for consistency with Series.
skipna : bool, default True

Returns
-------
numpy.ndarray

See Also
--------
numpy.ndarray.argmin : Return indices of the minimum values along
the given axis.
"""
nv.validate_minmax_axis(axis)
nv.validate_argmax_with_skipna(skipna, args, kwargs)
return nanops.nanargmin(self._values, skipna=skipna)
Expand Down