Skip to content

DOC: Correct Series.nonzero docstring #8247

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 1 commit into from
Sep 12, 2014
Merged
Changes from all 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
22 changes: 19 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,27 @@ def compress(self, condition, axis=0, out=None, **kwargs):

def nonzero(self):
"""
return the a boolean array of the underlying data is nonzero
Return the indices of the elements that are non-zero

See also
This method is equivalent to calling `numpy.nonzero` on the
series data. For compatability with NumPy, the return value is
the same (a tuple with an array of indices for each dimension),
Copy link
Contributor

Choose a reason for hiding this comment

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

leave this line alone. This makes a link back to the numpy docs (and pretty sure requires the ndarray part). @jorisvandenbossche ?

Copy link
Member

Choose a reason for hiding this comment

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

It just depends if you want to refer to a toplevel function or an array method.
And in this case, they both exists, but the docs of np.nonzero is more elaborate (np.ndarray.nonzero also just refers to np.nonzero). So for here, changing to numpy.nonzero is good.

but it will always be a one-item tuple because series only have
one dimension.

Examples
--------
>>> s = pd.Series([0, 3, 0, 4])
>>> s.nonzero()
(array([1, 3]),)
>>> s.iloc[s.nonzero()[0]]
1 3
3 4
dtype: int64

See Also
--------
numpy.ndarray.nonzero
numpy.nonzero
"""
return self.values.nonzero()

Expand Down