-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Update series apply docstring. GH22459 #22510
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
Changes from 5 commits
9b17810
817379f
5baa4fd
d07650f
0eb4e8c
d5c13b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. may be we can say "Python function or NumPy ufunc to apply."? |
||
convert_dtype : bool, default True | ||
Try to find better dtype for elementwise function results. If | ||
False, leave as dtype=object | ||
False, leave as dtype=object. | ||
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 passed to func after the series value. | ||
**kwds | ||
Additional keyword arguments passed to func. | ||
|
||
Returns | ||
------- | ||
y : Series or DataFrame if func returns a Series | ||
Series or DataFrame | ||
If func returns a Series object the result will be a DataFrame. | ||
|
||
See also | ||
See Also | ||
-------- | ||
Series.map: For element-wise operations | ||
Series.agg: only perform aggregating type operations | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Can you capitalize all the first letters of the descriptions |
||
|
||
Examples | ||
-------- | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I think it's more readable if we have all |
||
>>> series | ||
>>> s | ||
London 20 | ||
New York 21 | ||
Helsinki 12 | ||
|
@@ -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 commentThe 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 |
||
>>> series.apply(square) | ||
>>> s.apply(square) | ||
London 400 | ||
New York 441 | ||
Helsinki 144 | ||
|
@@ -3153,7 +3155,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): | |
Square the values by passing an anonymous function as an | ||
argument to ``apply()``. | ||
|
||
>>> series.apply(lambda x: x**2) | ||
>>> s.apply(lambda x: x**2) | ||
London 400 | ||
New York 441 | ||
Helsinki 144 | ||
|
@@ -3166,7 +3168,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): | |
>>> def subtract_custom_value(x, custom_value): | ||
... return x-custom_value | ||
|
||
>>> series.apply(subtract_custom_value, args=(5,)) | ||
>>> s.apply(subtract_custom_value, args=(5,)) | ||
London 15 | ||
New York 16 | ||
Helsinki 7 | ||
|
@@ -3180,21 +3182,19 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): | |
... x+=kwargs[month] | ||
... return x | ||
|
||
>>> series.apply(add_custom_values, june=30, july=20, august=25) | ||
>>> s.apply(add_custom_values, june=30, july=20, august=25) | ||
London 95 | ||
New York 96 | ||
Helsinki 87 | ||
dtype: int64 | ||
|
||
Use a function from the Numpy library. | ||
|
||
>>> series.apply(np.log) | ||
>>> s.apply(np.log) | ||
London 2.995732 | ||
New York 3.044522 | ||
Helsinki 2.484907 | ||
dtype: float64 | ||
|
||
|
||
""" | ||
if len(self) == 0: | ||
return self._constructor(dtype=self.dtype, | ||
|
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.