Skip to content

DOC: update the Seriex.idxmax and Series.idxmin docstring #20174

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 5 commits into from
Mar 12, 2018
Merged
Changes from 3 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
101 changes: 84 additions & 17 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,22 +1326,31 @@ def duplicated(self, keep='first'):

def idxmin(self, axis=None, skipna=True, *args, **kwargs):
"""
Index *label* of the first occurrence of minimum of values.
Return the row label of the minimum value.

If multiple values equal the minimum, the first row label with that
value is returned.

Parameters
----------
skipna : boolean, default True
Exclude NA/null values. If the entire Series is NA, the result
will be NA.
axis : int, default 0
For compatibility with DataFrame.idxmin. Redundant for application
on Series.
*args, **kwargs
Additional keywors have no effect but might be accepted
for compatibility with NumPy.

Returns
-------
idxmin : Index of minimum of values.

Raises
------
ValueError
* If the Series is empty

Returns
-------
idxmin : Index of minimum of values
If the Series is empty.

Notes
-----
Expand All @@ -1351,33 +1360,66 @@ def idxmin(self, axis=None, skipna=True, *args, **kwargs):

See Also
--------
DataFrame.idxmin
numpy.ndarray.argmin
numpy.argmin : Return indices of the minimum values
along the given axis.
DataFrame.idxmin : Return index of first occurrence of minimum
over requested axis.
Series.idxmax : Return index *label* of the first occurrence
of maximum of values.

Examples
--------
>>> s = pd.Series(data=[1, None, 4, 1],
... index=['A' ,'B' ,'C' ,'D'])
>>> s
A 1.0
B NaN
C 4.0
D 1.0
dtype: float64

>>> s.idxmin()
'A'

If skipna=False and there is an NA value in the data,
the function returns ``nan``.

>>> s.idxmin(skipna=False)
nan
"""
skipna = nv.validate_argmin_with_skipna(skipna, args, kwargs)
i = nanops.nanargmin(com._values_from_object(self), skipna=skipna)
if i == -1:
return np.nan
return self.index[i]

def idxmax(self, axis=None, skipna=True, *args, **kwargs):
def idxmax(self, axis=0, skipna=True, *args, **kwargs):
"""
Index *label* of the first occurrence of maximum of values.
Return the row label of the maximum value.

If multiple values equal the maximum, the first row label with that
value is returned.

Parameters
----------
skipna : boolean, default True
Exclude NA/null values. If the entire Series is NA, the result
will be NA.
axis : int, default 0
For compatibility with DataFrame.idxmax. Redundant for application
on Series.
*args, **kwargs
Additional keywors have no effect but might be accepted
for compatibility with NumPy.

Returns
-------
idxmax : Index of maximum of values.

Raises
------
ValueError
* If the Series is empty

Returns
-------
idxmax : Index of maximum of values
If the Series is empty.

Notes
-----
Expand All @@ -1387,8 +1429,33 @@ def idxmax(self, axis=None, skipna=True, *args, **kwargs):

See Also
--------
DataFrame.idxmax
numpy.ndarray.argmax
numpy.argmax : Return indices of the maximum values
along the given axis.
DataFrame.idxmax : Return index of first occurrence of maximum
over requested axis.
Series.idxmin : Return index *label* of the first occurrence
of minimum of values.

Examples
--------
>>> s = pd.Series(data=[1, None, 4, 3, 4],
... index=['A', 'B', 'C', 'D', 'E'])
>>> s
A 1.0
B NaN
C 4.0
D 3.0
E 4.0
dtype: float64

>>> s.idxmax()
'C'

If skipna=False and there is an NA value in the data,
the function returns ``nan``.

>>> s.idxmax(skipna=False)
nan
"""
skipna = nv.validate_argmax_with_skipna(skipna, args, kwargs)
i = nanops.nanargmax(com._values_from_object(self), skipna=skipna)
Expand Down