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

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

Merged
merged 18 commits into from
Mar 6, 2020
Merged
Changes from 11 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
55 changes: 26 additions & 29 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,16 +927,23 @@ 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",
position="third",
example_values="2",
)
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,32 +953,32 @@ 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.
numpy.ndarray.arg{op} : Equivalent method for numpy arrays.
Series.arg{oppose} : Similar method, but returning the {oppose}imum.
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
Cinnamon Toast Crunch 120.0
Cocoa Puff 110.0
dtype: float64

>>> s.argmax()
2
>>> s.arg{op}()
{example_values}

The maximum cereal calories is in the third element,
The {op}imum cereal calories is the {position} element,
since series is zero-indexed.
"""
nv.validate_minmax_axis(axis)
Expand Down Expand Up @@ -1019,25 +1026,15 @@ 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",
position="first",
example_values="0",
)
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