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: Update series apply docstring. GH22459 #22510

Merged
merged 6 commits into from
Nov 24, 2018
Merged

DOC: Update series apply docstring. GH22459 #22510

merged 6 commits into from
Nov 24, 2018

Conversation

eldritchideen
Copy link
Contributor

@eldritchideen eldritchideen commented Aug 26, 2018

Updated Series.apply docstring to resolve errors raised from scripts/validate_docstrings.py from #22459.

@codecov
Copy link

codecov bot commented Aug 26, 2018

Codecov Report

Merging #22510 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22510   +/-   ##
=======================================
  Coverage   92.29%   92.29%           
=======================================
  Files         161      161           
  Lines       51498    51498           
=======================================
  Hits        47530    47530           
  Misses       3968     3968
Flag Coverage Δ
#multiple 90.69% <ø> (ø) ⬆️
#single 42.43% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/series.py 93.68% <ø> (ø) ⬆️

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 f2839fe...d5c13b2. Read the comment docs.

args : tuple
Positional arguments to pass to function in addition to the value
Additional keyword arguments will be passed as keywords to the function
Positional arguments to pass to func in addition to the value.
Copy link
Member

Choose a reason for hiding this comment

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

"in addition to the value" - can we clarify what that means?

Positional arguments to pass to function in addition to the value
Additional keyword arguments will be passed as keywords to the function
Positional arguments to pass to func in addition to the value.
**kwds : dict
Copy link
Member

@gfyoung gfyoung Aug 27, 2018

Choose a reason for hiding this comment

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

@datapythonista : I wonder if we should standardize and use **kwargs everywhere.

(@eldritchideen : Don't worry about this comment. This is a larger question beyond this PR for the time being.)

Copy link
Member

Choose a reason for hiding this comment

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

In terms of documentation, the standard we defined was to always document *args and **kwargs if present, showing the stars in the name, but without the type (it'll always be tuple and dict).

Not sure if you mean using kwargs instead of kwds, or which standardization are you proposing here, but I'm +1 on being consistent everywhere.

I see that in this case args needs to be provided as a tuple (not as positional arguments) and kwds needs to be provided as keyword arguments (not as a dict). Not sure if there is a reason for this, but if it's not, I'd be in favor of changing it to be consistent (in a separate PR). @jreback ?

Copy link
Member

Choose a reason for hiding this comment

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

@datapythonista : Indeed, I was referring to using kwargs across the board. I'm also in favor of consistency in general.

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good to me, and afaik it should be a backward compatible change in all cases, so +1 on this. Do you want to create an issue?

@gfyoung gfyoung requested a review from datapythonista August 27, 2018 09:32
@gfyoung gfyoung added Docs Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels Aug 27, 2018
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.

Changes look good to me, after considering @gfyoung comments, and removing the type (dict) of **kwds. Thanks @eldritchideen

Positional arguments to pass to function in addition to the value
Additional keyword arguments will be passed as keywords to the function
Positional arguments to pass to func in addition to the value.
**kwds : dict
Copy link
Member

Choose a reason for hiding this comment

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

In terms of documentation, the standard we defined was to always document *args and **kwargs if present, showing the stars in the name, but without the type (it'll always be tuple and dict).

Not sure if you mean using kwargs instead of kwds, or which standardization are you proposing here, but I'm +1 on being consistent everywhere.

I see that in this case args needs to be provided as a tuple (not as positional arguments) and kwds needs to be provided as keyword arguments (not as a dict). Not sure if there is a reason for this, but if it's not, I'd be in favor of changing it to be consistent (in a separate PR). @jreback ?

@eldritchideen
Copy link
Contributor Author

@datapythonista I removed the type from the **kwds parameter. I also agree that it should be renamed to **kwargs to be more consistent with the rest of the code base.

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.

Thanks for the changes @eldritchideen . Can you add the clarification to the args parameter @gfyoung asked? I don't think it's clear enough either.

Also, it'd be great if you can change couple of few things to make the docstring follow all our guidelines:

  • Remove the colon after **kwds
  • In the Returns section, remove the y : and leave just Series or DataFrame adding the description (and clarifications about the type) to the next line (indented)
  • Add a period at the end of each See Also item (and capitalize the A in Also in the title)
  • Remove the blank line after the Examples title.
  • Rename the variable series by s in the examples.

Thank you!

@pep8speaks
Copy link

pep8speaks commented Sep 4, 2018

Hello @eldritchideen! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on September 04, 2018 at 10:56 Hours UTC

@eldritchideen
Copy link
Contributor Author

I have updated the Series.apply docstring based on review feedback. Thanks @datapythonista and @gfyoung

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.

Looking better, there are some more changes that we can do (mainly to the original code) to make it look perfect.


Parameters
----------
func : function
convert_dtype : boolean, default True
Python function or NumPy ufunc.
Copy link
Member

Choose a reason for hiding this comment

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

may be we can say "Python function or NumPy ufunc to apply."?

Series.transform: only perform transforming type operations
Series.map: For element-wise operations.
Series.agg: only perform aggregating type operations.
Series.transform: only perform transforming type operations.
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 capitalize all the first letters of the descriptions

@@ -3144,7 +3146,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):

>>> def square(x):
... return x**2
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 fix the PEP-8 of all examples please? There are missing spaces around all the ** , one - and one +=. I know it's from the original code, but let's get it fixed.

Create a series with typical summer temperatures for each city.

>>> series = pd.Series([20, 21, 12], index=['London',
>>> s = pd.Series([20, 21, 12], index=['London',
... 'New York','Helsinki'])
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 more readable if we have all index in the next line.

@@ -3104,36 +3104,38 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
"""
Invoke function on values of Series. Can be ufunc (a NumPy function
that applies to the entire Series) or a Python function that only works
on single values
on single values.
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 have a single line description first, and the rest later. You have the documentation about this here:
https://pandas.pydata.org/pandas-docs/stable/contributing_docstring.html

If you run ./scripts/validate_docstrings.py pandas.Series.apply should report an error about it.

@jorisvandenbossche
Copy link
Member

@eldritchideen do you have time to update this PR based on the comments?

@datapythonista datapythonista self-assigned this Nov 3, 2018
@WillAyd
Copy link
Member

WillAyd commented Nov 23, 2018

@datapythonista I see the self assignment on this - are you actually working this one?

@datapythonista
Copy link
Member

I forgot about it, but fixed the pending issues now. Can you take a look and merge if everything is ok (or fix any outstanding issue, as the PR is discontinued)?

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.

Thanks @datapythonista will merge on green

@datapythonista datapythonista merged commit d865e52 into pandas-dev:master Nov 24, 2018
@datapythonista
Copy link
Member

thanks @eldritchideen

Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants