From c791a849aeb950d831b6044dc26fe39a4aa9f187 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Sun, 11 Mar 2018 13:07:01 +0100 Subject: [PATCH] DOC: pd.core.window.Expanding.kurt docstring (split from pd.core.Rolling.kurt) (#20064) --- pandas/core/window.py | 73 ++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index c41b07759d555..5294cdfd5662d 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -926,28 +926,7 @@ def skew(self, **kwargs): Notes ----- - A minimum of 4 periods is required for the rolling calculation. - - Examples - -------- - The below example will show a rolling calculation with a window size of - four matching the equivalent function call using `scipy.stats`. - - >>> arr = [1, 2, 3, 4, 999] - >>> fmt = "{0:.6f}" # limit the printed precision to 6 digits - >>> import scipy.stats - >>> print(fmt.format(scipy.stats.kurtosis(arr[:-1], bias=False))) - -1.200000 - >>> print(fmt.format(scipy.stats.kurtosis(arr[1:], bias=False))) - 3.999946 - >>> s = pd.Series(arr) - >>> s.rolling(4).kurt() - 0 NaN - 1 NaN - 2 NaN - 3 -1.200000 - 4 3.999946 - dtype: float64 + A minimum of 4 periods is required for the %(name)s calculation. """) def kurt(self, **kwargs): @@ -1269,6 +1248,31 @@ def var(self, ddof=1, *args, **kwargs): def skew(self, **kwargs): return super(Rolling, self).skew(**kwargs) + _agg_doc = dedent(""" + Examples + -------- + + The example below will show a rolling calculation with a window size of + four matching the equivalent function call using `scipy.stats`. + + >>> arr = [1, 2, 3, 4, 999] + >>> fmt = "{0:.6f}" # limit the printed precision to 6 digits + >>> import scipy.stats + >>> print(fmt.format(scipy.stats.kurtosis(arr[:-1], bias=False))) + -1.200000 + >>> print(fmt.format(scipy.stats.kurtosis(arr[1:], bias=False))) + 3.999946 + >>> s = pd.Series(arr) + >>> s.rolling(4).kurt() + 0 NaN + 1 NaN + 2 NaN + 3 -1.200000 + 4 3.999946 + dtype: float64 + """) + + @Appender(_agg_doc) @Substitution(name='rolling') @Appender(_shared_docs['kurt']) def kurt(self, **kwargs): @@ -1508,6 +1512,31 @@ def var(self, ddof=1, *args, **kwargs): def skew(self, **kwargs): return super(Expanding, self).skew(**kwargs) + _agg_doc = dedent(""" + Examples + -------- + + The example below will show an expanding calculation with a window size of + four matching the equivalent function call using `scipy.stats`. + + >>> arr = [1, 2, 3, 4, 999] + >>> import scipy.stats + >>> fmt = "{0:.6f}" # limit the printed precision to 6 digits + >>> print(fmt.format(scipy.stats.kurtosis(arr[:-1], bias=False))) + -1.200000 + >>> print(fmt.format(scipy.stats.kurtosis(arr, bias=False))) + 4.999874 + >>> s = pd.Series(arr) + >>> s.expanding(4).kurt() + 0 NaN + 1 NaN + 2 NaN + 3 -1.200000 + 4 4.999874 + dtype: float64 + """) + + @Appender(_agg_doc) @Substitution(name='expanding') @Appender(_shared_docs['kurt']) def kurt(self, **kwargs):