From 097da792db9be63d396758a542bc3e4d5f69395a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Fri, 30 Jun 2023 17:07:51 +0200 Subject: [PATCH 1/6] Examples Rolling.max, cov, skew, apply --- ci/code_checks.sh | 4 --- pandas/core/window/doc.py | 8 ++--- pandas/core/window/rolling.py | 57 +++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index a0fb7ab6e411d..27904af9d0407 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -131,10 +131,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas_object \ pandas.api.interchange.from_dataframe \ pandas.DatetimeIndex.snap \ - pandas.core.window.rolling.Rolling.max \ - pandas.core.window.rolling.Rolling.cov \ - pandas.core.window.rolling.Rolling.skew \ - pandas.core.window.rolling.Rolling.apply \ pandas.core.window.rolling.Window.mean \ pandas.core.window.rolling.Window.sum \ pandas.core.window.rolling.Window.var \ diff --git a/pandas/core/window/doc.py b/pandas/core/window/doc.py index 2a5cbc04921fa..c3ccb471c973e 100644 --- a/pandas/core/window/doc.py +++ b/pandas/core/window/doc.py @@ -24,10 +24,10 @@ def create_section_header(header: str) -> str: template_see_also = dedent( """ - pandas.Series.{window_method} : Calling {window_method} with Series data. - pandas.DataFrame.{window_method} : Calling {window_method} with DataFrames. - pandas.Series.{agg_method} : Aggregating {agg_method} for Series. - pandas.DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n + Series.{window_method} : Calling {window_method} with Series data. + DataFrame.{window_method} : Calling {window_method} with DataFrames. + Series.{agg_method} : Aggregating {agg_method} for Series. + DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n """ ).replace("\n", "", 1) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index f4d733423b3ae..33369a0442d5e 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1900,7 +1900,19 @@ def count(self, numeric_only: bool = False): create_section_header("Returns"), template_returns, create_section_header("See Also"), - template_see_also[:-1], + template_see_also, + create_section_header("Examples"), + dedent( + """ + >>> ser = pd.Series([1, 6, 5, 4]) + >>> ser.rolling(2).apply(lambda s: s.sum() - s.min()) + 0 NaN + 1 6.0 + 2 6.0 + 3 5.0 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="custom aggregation function", agg_method="apply", @@ -2008,7 +2020,19 @@ def sum( create_section_header("See Also"), template_see_also, create_section_header("Notes"), - numba_notes[:-1], + numba_notes, + create_section_header("Examples"), + dedent( + """ + >>> ser = pd.Series([1, 2, 3, 4]) + >>> ser.rolling(2).max() + 0 NaN + 1 2.0 + 2 3.0 + 3 4.0 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="maximum", agg_method="max", @@ -2289,6 +2313,20 @@ def var( template_see_also, create_section_header("Notes"), "A minimum of three periods is required for the rolling calculation.\n", + create_section_header("Examples"), + dedent( + """ + >>> ser = pd.Series([1, 5, 2, 7, 12, 6]) + >>> ser.rolling(3).skew() + 0 NaN + 1 NaN + 2 1.293343e+00 + 3 -5.855827e-01 + 4 -1.278977e-16 + 5 1.545393e+00 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="unbiased skewness", agg_method="skew", @@ -2538,7 +2576,20 @@ def rank( create_section_header("Returns"), template_returns, create_section_header("See Also"), - template_see_also[:-1], + template_see_also, + create_section_header("Examples"), + dedent( + """ + >>> ser1 = pd.Series([1, 2, 3, 4]) + >>> ser2 = pd.Series([1, 4, 5, 8]) + >>> ser1.rolling(2).cov(ser2) + 0 NaN + 1 1.5 + 2 0.5 + 3 1.5 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="sample covariance", agg_method="cov", From 1001ed406a48ae16d3fb0e4ec5ca8b8aa3da38d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Fri, 30 Jun 2023 19:52:22 +0200 Subject: [PATCH 2/6] correct skew --- pandas/core/window/rolling.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 33369a0442d5e..7fbb91c376b9d 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -2312,7 +2312,11 @@ def var( "scipy.stats.skew : Third moment of a probability density.\n", template_see_also, create_section_header("Notes"), - "A minimum of three periods is required for the rolling calculation.\n", + dedent( + """ + A minimum of three periods is required for the rolling calculation.\n + """ + ).replace("\n", "", 1), create_section_header("Examples"), dedent( """ From 6882d04e9c107075e29caa98f331aee7e2f1fdcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Sun, 2 Jul 2023 18:20:19 +0200 Subject: [PATCH 3/6] Changing format skew --- pandas/core/window/rolling.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 7fbb91c376b9d..be5af6d049f6d 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -2320,6 +2320,7 @@ def var( create_section_header("Examples"), dedent( """ + >>> pd.set_option("display.float_format", None) >>> ser = pd.Series([1, 5, 2, 7, 12, 6]) >>> ser.rolling(3).skew() 0 NaN From 25600de6353940b5f4f8990c0b4d14d8972b6c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 3 Jul 2023 14:20:51 +0200 Subject: [PATCH 4/6] Trying to fix skew --- pandas/core/window/rolling.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index be5af6d049f6d..a8083e1c7aa7e 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -2320,15 +2320,14 @@ def var( create_section_header("Examples"), dedent( """ - >>> pd.set_option("display.float_format", None) >>> ser = pd.Series([1, 5, 2, 7, 12, 6]) - >>> ser.rolling(3).skew() - 0 NaN - 1 NaN - 2 1.293343e+00 - 3 -5.855827e-01 - 4 -1.278977e-16 - 5 1.545393e+00 + >>> ser.rolling(3).skew().round(6) + 0 NaN + 1 NaN + 2 1.293343 + 3 -0.585583 + 4 0.000000 + 5 1.545393 dtype: float64 """ ).replace("\n", "", 1), From c1edff97e6e73839bcef21ca65e849d1c16160e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 4 Jul 2023 09:47:14 +0200 Subject: [PATCH 5/6] Removed replace() --- pandas/core/window/rolling.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index a8083e1c7aa7e..bf68c8fdcf7da 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1903,7 +1903,7 @@ def count(self, numeric_only: bool = False): template_see_also, create_section_header("Examples"), dedent( - """ + """\ >>> ser = pd.Series([1, 6, 5, 4]) >>> ser.rolling(2).apply(lambda s: s.sum() - s.min()) 0 NaN @@ -1912,7 +1912,7 @@ def count(self, numeric_only: bool = False): 3 5.0 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="custom aggregation function", agg_method="apply", @@ -2023,7 +2023,7 @@ def sum( numba_notes, create_section_header("Examples"), dedent( - """ + """\ >>> ser = pd.Series([1, 2, 3, 4]) >>> ser.rolling(2).max() 0 NaN @@ -2032,7 +2032,7 @@ def sum( 3 4.0 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="maximum", agg_method="max", @@ -2319,7 +2319,7 @@ def var( ).replace("\n", "", 1), create_section_header("Examples"), dedent( - """ + """\ >>> ser = pd.Series([1, 5, 2, 7, 12, 6]) >>> ser.rolling(3).skew().round(6) 0 NaN @@ -2330,7 +2330,7 @@ def var( 5 1.545393 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="unbiased skewness", agg_method="skew", @@ -2583,7 +2583,7 @@ def rank( template_see_also, create_section_header("Examples"), dedent( - """ + """\ >>> ser1 = pd.Series([1, 2, 3, 4]) >>> ser2 = pd.Series([1, 4, 5, 8]) >>> ser1.rolling(2).cov(ser2) @@ -2593,7 +2593,7 @@ def rank( 3 1.5 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="sample covariance", agg_method="cov", From b513331939e5586ce0de2112c8312055ab578421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 4 Jul 2023 16:14:12 +0200 Subject: [PATCH 6/6] Remove replace() correct doc.py links --- pandas/core/window/doc.py | 8 ++++---- pandas/core/window/rolling.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/window/doc.py b/pandas/core/window/doc.py index c3ccb471c973e..2a5cbc04921fa 100644 --- a/pandas/core/window/doc.py +++ b/pandas/core/window/doc.py @@ -24,10 +24,10 @@ def create_section_header(header: str) -> str: template_see_also = dedent( """ - Series.{window_method} : Calling {window_method} with Series data. - DataFrame.{window_method} : Calling {window_method} with DataFrames. - Series.{agg_method} : Aggregating {agg_method} for Series. - DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n + pandas.Series.{window_method} : Calling {window_method} with Series data. + pandas.DataFrame.{window_method} : Calling {window_method} with DataFrames. + pandas.Series.{agg_method} : Aggregating {agg_method} for Series. + pandas.DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n """ ).replace("\n", "", 1) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index bf68c8fdcf7da..9778651814b23 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -2316,7 +2316,7 @@ def var( """ A minimum of three periods is required for the rolling calculation.\n """ - ).replace("\n", "", 1), + ), create_section_header("Examples"), dedent( """\