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 Series nsmallest and nlargest docstring/doctests #22731

Merged
merged 5 commits into from
Sep 18, 2018

Conversation

Moisan
Copy link
Contributor

@Moisan Moisan commented Sep 17, 2018

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

Based on #22459. Fix the docstring for Series.nsmallest and Series.nlargest. I did both together since the same example could be used. I removed both from the skipped doctests in ci/doctests.sh.

I also found out about the "all" option for the keep parameter which was surprisingly not documented.

@pep8speaks
Copy link

pep8speaks commented Sep 17, 2018

Hello @Moisan! Thanks for updating the PR.

Comment last updated on September 18, 2018 at 01:46 Hours UTC

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Minor comments

- ``first`` : take the first occurrences based on the index order
- ``last`` : take the last occurrences based on the index order
- ``all`` : keep all occurrences. This can result in a Series of
size larger than `n`.
Copy link
Member

Choose a reason for hiding this comment

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

Is the period here on the last bullet required to pass the docstring validation as-is? Shouldn't be necessary but if that's the intent here just something we should address separately @datapythonista

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 confirm that the validation fails if the last period is not present.

Brunei 434000
dtype: int64

>>> s.nlargest(3)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be nice to have just a quick one-liner to highlight the difference between this and the subsequent example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean a comment at the end of the line?

Copy link
Member

Choose a reason for hiding this comment

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

No just some text in between the examples to call out what the user should be looking at

@WillAyd WillAyd added the Docs label Sep 17, 2018
Brunei 434000
dtype: int64

The n largest elements where n=3 with all duplicates kept. Note that the
Copy link
Contributor

Choose a reason for hiding this comment

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

Monserat 5200
dtype: int64

The n largest elements where n=5 by default.
Copy link
Contributor

Choose a reason for hiding this comment

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

single backticks around n. Double backticks around n=5.

Brunei 434000
dtype: int64

The n largest elements where n=3. Default keep value is 'first' so
Copy link
Contributor

Choose a reason for hiding this comment

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

Same. Single backticks around keep.


The n largest elements where n=3. Default keep value is 'first' so
Malta will
be kept.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be on the same line as "Malta will"

Malta 434000
dtype: int64

The n largest elements where n=3 and keeping the last duplicates.
Copy link
Contributor

Choose a reason for hiding this comment

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

backticks.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Think this is a nice update so lgtm

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Great changes, suggested couple of small things, but other than that looks really good.

@@ -2789,16 +2837,19 @@ def nsmallest(self, n=5, keep='first'):
Parameters
----------
n : int
Copy link
Member

Choose a reason for hiding this comment

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

can you add the default here?

- ``last`` : take the last occurrence.
n : int, default 5
Return this many descending sorted values.
keep : str, default 'first'
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to keep {'first', 'last', 'all'}, as I don't think there is any other value allowed. That applies to both docstrings.

@@ -2762,23 +2765,68 @@ def nlargest(self, n=5, keep='first'):

See Also
--------
Series.nsmallest
Series.nsmallest: Get the `n` smallest elements.
Copy link
Member

Choose a reason for hiding this comment

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

I'd add sort_values and head here, as they're mentioned in the notes. In both docstrings.

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

lgtm. Excellent work @Moisan, thank you!

@TomAugspurger
Copy link
Contributor

Passed on travis. Merging.

@TomAugspurger TomAugspurger merged commit fc25f7d into pandas-dev:master Sep 18, 2018
@Moisan Moisan deleted the docstring_nlargest_nsmallest branch September 18, 2018 15:04
aeltanawy pushed a commit to aeltanawy/pandas that referenced this pull request Sep 20, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants