Skip to content

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

Merged
merged 1 commit into from
Jan 23, 2018

Conversation

drorata
Copy link
Contributor

@drorata drorata commented Jan 20, 2018

@codecov
Copy link

codecov bot commented Jan 20, 2018

Codecov Report

Merging #19324 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.91% <100%> (-0.03%) ⬇️
#single 41.72% <100%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/series.py 94.6% <100%> (ø) ⬆️
pandas/plotting/_converter.py 65.22% <0%> (-1.74%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ba65ca...75e2ee4. Read the comment docs.

@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

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.


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
Copy link
Contributor

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?

Copy link
Contributor

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)

Copy link
Contributor Author

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.

@@ -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
Copy link
Contributor

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

@@ -508,6 +509,15 @@ def nonzero(self):
3 4
dtype: int64

>>> s = pd.Series([0, 3, 0, 4])
Copy link
Contributor

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 jreback added Docs Indexing Related to indexing on series/frames, not to indexes themselves labels Jan 21, 2018
@drorata
Copy link
Contributor Author

drorata commented Jan 22, 2018

@jreback I have updated the PR

@jreback jreback added this to the 0.23.0 milestone Jan 23, 2018
@jreback jreback merged commit 9872d67 into pandas-dev:master Jan 23, 2018
@jreback
Copy link
Contributor

jreback commented Jan 23, 2018

thanks @drorata

@jreback jreback mentioned this pull request Jan 23, 2018
4 tasks
@drorata drorata deleted the fix-19312 branch January 23, 2018 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series.nonzero(): Returns locations, not indices
2 participants