-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
DOC: Update series apply docstring. GH22459 #22510
Conversation
Codecov Report
@@ Coverage Diff @@
## master #22510 +/- ##
=======================================
Coverage 92.29% 92.29%
=======================================
Files 161 161
Lines 51498 51498
=======================================
Hits 47530 47530
Misses 3968 3968
Continue to review full report at Codecov.
|
pandas/core/series.py
Outdated
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. |
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.
"in addition to the value" - can we clarify what that means?
pandas/core/series.py
Outdated
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 |
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.
@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.)
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.
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 ?
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.
@datapythonista : Indeed, I was referring to using kwargs
across the board. I'm also in favor of consistency in general.
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.
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?
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.
Changes look good to me, after considering @gfyoung comments, and removing the type (dict) of **kwds
. Thanks @eldritchideen
pandas/core/series.py
Outdated
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 |
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.
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 ?
@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. |
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.
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 they :
and leave justSeries 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 theA
inAlso
in the title) - Remove the blank line after the
Examples
title. - Rename the variable
series
bys
in the examples.
Thank you!
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 |
I have updated the Series.apply docstring based on review feedback. Thanks @datapythonista and @gfyoung |
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.
Looking better, there are some more changes that we can do (mainly to the original code) to make it look perfect.
pandas/core/series.py
Outdated
|
||
Parameters | ||
---------- | ||
func : function | ||
convert_dtype : boolean, default True | ||
Python function or NumPy ufunc. |
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.
may be we can say "Python function or NumPy ufunc to apply."?
pandas/core/series.py
Outdated
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. |
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.
Can you capitalize all the first letters of the descriptions
pandas/core/series.py
Outdated
@@ -3144,7 +3146,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): | |||
|
|||
>>> def square(x): | |||
... return x**2 |
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.
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.
pandas/core/series.py
Outdated
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']) |
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 think it's more readable if we have all index
in the next line.
pandas/core/series.py
Outdated
@@ -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. |
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.
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.
@eldritchideen do you have time to update this PR based on the comments? |
@datapythonista I see the self assignment on this - are you actually working this one? |
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)? |
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.
Thanks @datapythonista will merge on green
thanks @eldritchideen |
git diff upstream/master -u -- "*.py" | flake8 --diff
Updated
Series.apply
docstring to resolve errors raised from scripts/validate_docstrings.py from #22459.