-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Improve docs (GH19312) for Series.nonzero() #19324
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19324 +/- ##
==========================================
- Coverage 91.57% 91.54% -0.03%
==========================================
Files 150 150
Lines 48700 48700
==========================================
- Hits 44595 44583 -12
- Misses 4105 4117 +12
Continue to review full report at Codecov.
|
pandas/core/series.py
Outdated
@@ -490,13 +490,14 @@ def compress(self, condition, *args, **kwargs): | |||
|
|||
def nonzero(self): | |||
""" | |||
Return the indices of the elements that are non-zero | |||
Return the integer indices of the elements that are non-zero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we normally call these indexers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The confusion reflected in #19312 relates to the fact that the definitions are not clear. Personally, I don't know what are the different definitions. The index
of a Series
may be a default one; namely integers starting from 0
. Or, named indices. This PR stress in the documentation of nonzero
that it returns the integers.
pandas/core/series.py
Outdated
|
||
This method is equivalent to calling `numpy.nonzero` on the | ||
series data. For compatibility with NumPy, the return value is | ||
the same (a tuple with an array of indices for each dimension), | ||
but it will always be a one-item tuple because series only have | ||
one dimension. | ||
one dimension. Note that the method returns the *integer* indices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just repeating from above yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to add this to a Notes section (and you could move most of the above text there as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the addition and only stressed the properties of the returned value in the first one-liner. I guess some glossary could be helpful to clarify what are the differences between the different definitions.
pandas/core/series.py
Outdated
@@ -508,6 +509,15 @@ def nonzero(self): | |||
3 4 | |||
dtype: int64 | |||
|
|||
>>> s = pd.Series([0, 3, 0, 4]) | |||
>>> s.index=['a', 'b', 'c', 'd'] | |||
>>> s.nonzero() # same return although index of s is different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can put the comment before the example
pandas/core/series.py
Outdated
@@ -508,6 +509,15 @@ def nonzero(self): | |||
3 4 | |||
dtype: int64 | |||
|
|||
>>> s = pd.Series([0, 3, 0, 4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just directly construct the Series with the index, then show it
@jreback I have updated the PR |
thanks @drorata |
git diff upstream/master -u -- "*.py" | flake8 --diff