From 9b1781067735773279a2821ed4cdad0f367c30f7 Mon Sep 17 00:00:00 2001 From: Steven Cook Date: Sun, 26 Aug 2018 13:01:17 +1000 Subject: [PATCH 1/5] DOC: Updated Series.apply docstring. GH22459 --- pandas/core/series.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ab41954990412..b14440e76efe1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3104,17 +3104,19 @@ 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. + 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 to pass to func in addition to the value. + **kwds : dict + Additional keyword arguments will be passed to func. Returns ------- @@ -3193,8 +3195,6 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): New York 3.044522 Helsinki 2.484907 dtype: float64 - - """ if len(self) == 0: return self._constructor(dtype=self.dtype, From 817379fab72ecdb1c79c27709edb06aef5a9379e Mon Sep 17 00:00:00 2001 From: Steven Cook Date: Sun, 26 Aug 2018 13:04:11 +1000 Subject: [PATCH 2/5] DOC: Updated wording. --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index b14440e76efe1..6f0ab877d1eb9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3116,7 +3116,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): args : tuple Positional arguments to pass to func in addition to the value. **kwds : dict - Additional keyword arguments will be passed to func. + Additional keyword arguments passed to func. Returns ------- From 5baa4fdb84395e95fda4f774b0c739944219b2ab Mon Sep 17 00:00:00 2001 From: Steven Cook Date: Tue, 28 Aug 2018 20:14:52 +1000 Subject: [PATCH 3/5] DOC: Removed type from **kwds parameter. --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 6f0ab877d1eb9..8d8e24db2d2b0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3115,7 +3115,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): False, leave as dtype=object. args : tuple Positional arguments to pass to func in addition to the value. - **kwds : dict + **kwds : Additional keyword arguments passed to func. Returns From d07650f5a7a3a231da8f5d8ea453d73de5c8c1fe Mon Sep 17 00:00:00 2001 From: Steven Cook Date: Tue, 4 Sep 2018 20:54:10 +1000 Subject: [PATCH 4/5] DOC: Updated Series.apply docstring based on review feedback. --- pandas/core/series.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 8d8e24db2d2b0..1a62d29afe1e8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3114,28 +3114,28 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): Try to find better dtype for elementwise function results. If False, leave as dtype=object. args : tuple - Positional arguments to pass to func in addition to the value. - **kwds : + 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. 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']) - >>> series + >>> s London 20 New York 21 Helsinki 12 @@ -3146,7 +3146,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): >>> def square(x): ... return x**2 - >>> series.apply(square) + >>> s.apply(square) London 400 New York 441 Helsinki 144 @@ -3155,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 @@ -3168,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 @@ -3182,7 +3182,7 @@ 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 @@ -3190,7 +3190,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): 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 From 0eb4e8cb9bc28b7921d47d8c81e8e0e67e4ff7e1 Mon Sep 17 00:00:00 2001 From: Steven Cook Date: Tue, 4 Sep 2018 20:55:53 +1000 Subject: [PATCH 5/5] DOC: Removed trailing whitespace. --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1a62d29afe1e8..0efb22139f94f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3120,7 +3120,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): Returns ------- - Series or DataFrame + Series or DataFrame If func returns a Series object the result will be a DataFrame. See Also