From b096c8dfb4da50ecfdaa3d3e2b7c683e1153831f Mon Sep 17 00:00:00 2001 From: Matt Maybeno Date: Sat, 10 Mar 2018 12:44:16 -0800 Subject: [PATCH 1/4] DOC: update Rolling.std docstring --- pandas/core/window.py | 51 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index c41b07759d555..5cdbe0e62f5da 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -857,13 +857,58 @@ def median(self, **kwargs): return self._apply('roll_median_c', 'median', **kwargs) _shared_docs['std'] = dedent(""" - %(name)s standard deviation + Calculate %(name)s standard deviation. + + Normalized by N-1 by default. This can be changed using the ddof argument. Parameters ---------- ddof : int, default 1 Delta Degrees of Freedom. The divisor used in calculations - is ``N - ddof``, where ``N`` represents the number of elements.""") + is ``N - ddof``, where ``N`` represents the number of elements. + args + Under Review. + kwargs + Under Review. + + Returns + ------- + Series or DataFrame + Returned object type is determined by the caller of the %(name)s + calculation + + See Also + -------- + Series.%(name)s : Calling object with Series data + DataFrame.%(name)s : Calling object with DataFrames + Series.std : Equivalent method for Series + DataFrame.std : Equivalent method for DataFrame + numpy.std : Equivalent method for Numpy array + + Notes + ----- + A minimum of 1 periods is required for the rolling calculation. + + Examples + -------- + The below example will show a rolling example + + >>> s = pd.Series((5,5,5,5,6,7,9,10,5,5,5,5)) + >>> s.rolling(3).std(1) + 0 NaN + 1 NaN + 2 0.000000 + 3 0.000000 + 4 0.577350 + 5 1.000000 + 6 1.527525 + 7 1.527525 + 8 2.645751 + 9 2.886751 + 10 0.000000 + 11 0.000000 + dtype: float64 + """) def std(self, ddof=1, *args, **kwargs): nv.validate_window_func('std', args, kwargs) @@ -1250,7 +1295,6 @@ def median(self, **kwargs): return super(Rolling, self).median(**kwargs) @Substitution(name='rolling') - @Appender(_doc_template) @Appender(_shared_docs['std']) def std(self, ddof=1, *args, **kwargs): nv.validate_rolling_func('std', args, kwargs) @@ -1489,7 +1533,6 @@ def median(self, **kwargs): return super(Expanding, self).median(**kwargs) @Substitution(name='expanding') - @Appender(_doc_template) @Appender(_shared_docs['std']) def std(self, ddof=1, *args, **kwargs): nv.validate_expanding_func('std', args, kwargs) From 96ab1ede4f61900dcb21588673677f457deeb644 Mon Sep 17 00:00:00 2001 From: Matt Maybeno Date: Sat, 10 Mar 2018 13:09:47 -0800 Subject: [PATCH 2/4] Addressing comments --- pandas/core/window.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index 5cdbe0e62f5da..afa9d66b7b2dc 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -859,23 +859,23 @@ def median(self, **kwargs): _shared_docs['std'] = dedent(""" Calculate %(name)s standard deviation. - Normalized by N-1 by default. This can be changed using the ddof argument. + Normalized by N-1 by default. This can be changed using the `ddof` + argument. Parameters ---------- ddof : int, default 1 Delta Degrees of Freedom. The divisor used in calculations is ``N - ddof``, where ``N`` represents the number of elements. - args + *args Under Review. - kwargs + **kwargs Under Review. Returns ------- - Series or DataFrame - Returned object type is determined by the caller of the %(name)s - calculation + Returns the same object type as determined by the caller of the %(name)s + calculation. See Also -------- @@ -891,10 +891,8 @@ def median(self, **kwargs): Examples -------- - The below example will show a rolling example - - >>> s = pd.Series((5,5,5,5,6,7,9,10,5,5,5,5)) - >>> s.rolling(3).std(1) + >>> s = pd.Series((5, 5, 5, 5, 6, 7, 9, 10, 5, 5, 5, 5)) + >>> s.rolling(3).std() 0 NaN 1 NaN 2 0.000000 @@ -908,6 +906,20 @@ def median(self, **kwargs): 10 0.000000 11 0.000000 dtype: float64 + >>> s.expanding(3).std() + 0 NaN + 1 NaN + 2 0.000000 + 3 0.000000 + 4 0.447214 + 5 0.836660 + 6 1.527525 + 7 2.000000 + 8 1.936492 + 9 1.873796 + 10 1.814086 + 11 1.758098 + dtype: float64 """) def std(self, ddof=1, *args, **kwargs): From f8bdc68d69bd3fe2f24da9a959cc10d250d6c567 Mon Sep 17 00:00:00 2001 From: Matt Maybeno Date: Sun, 11 Mar 2018 08:07:04 -0700 Subject: [PATCH 3/4] Addressing comments 2 --- pandas/core/window.py | 54 ++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index afa9d66b7b2dc..854488827076e 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -867,15 +867,13 @@ def median(self, **kwargs): ddof : int, default 1 Delta Degrees of Freedom. The divisor used in calculations is ``N - ddof``, where ``N`` represents the number of elements. - *args - Under Review. - **kwargs - Under Review. + *args, **kwargs + For NumPy compatibility. No additional arguments are used. Returns ------- - Returns the same object type as determined by the caller of the %(name)s - calculation. + Series or DataFrame + Returns the same object type as the caller of the %(name)s calculation. See Also -------- @@ -887,38 +885,32 @@ def median(self, **kwargs): Notes ----- + The default `ddof` of 1 used in Series.var is different than the default + `ddof` of 0 in numpy.var. + A minimum of 1 periods is required for the rolling calculation. Examples -------- - >>> s = pd.Series((5, 5, 5, 5, 6, 7, 9, 10, 5, 5, 5, 5)) + >>> s = pd.Series([5, 5, 6, 7, 5, 5, 5]) >>> s.rolling(3).std() - 0 NaN - 1 NaN - 2 0.000000 - 3 0.000000 - 4 0.577350 - 5 1.000000 - 6 1.527525 - 7 1.527525 - 8 2.645751 - 9 2.886751 - 10 0.000000 - 11 0.000000 + 0 NaN + 1 NaN + 2 0.577350 + 3 1.000000 + 4 1.000000 + 5 1.154701 + 6 0.000000 dtype: float64 + >>> s.expanding(3).std() - 0 NaN - 1 NaN - 2 0.000000 - 3 0.000000 - 4 0.447214 - 5 0.836660 - 6 1.527525 - 7 2.000000 - 8 1.936492 - 9 1.873796 - 10 1.814086 - 11 1.758098 + 0 NaN + 1 NaN + 2 0.577350 + 3 0.957427 + 4 0.894427 + 5 0.836660 + 6 0.786796 dtype: float64 """) From a1a756aef92b73fcac6ce90d6411582dd940036f Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 12 Mar 2018 11:03:30 -0500 Subject: [PATCH 4/4] var -> std --- pandas/core/window.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index 854488827076e..b5d386eff2423 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -885,10 +885,10 @@ def median(self, **kwargs): Notes ----- - The default `ddof` of 1 used in Series.var is different than the default - `ddof` of 0 in numpy.var. + The default `ddof` of 1 used in Series.std is different than the default + `ddof` of 0 in numpy.std. - A minimum of 1 periods is required for the rolling calculation. + A minimum of one period is required for the rolling calculation. Examples --------