From d54a6a52f3497cb4ef15d0e1c0d74156f6bfcc28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 3 Jul 2023 16:41:12 +0200 Subject: [PATCH 1/5] Examples Window.mean, sum, var, std --- ci/code_checks.sh | 4 -- pandas/core/window/rolling.py | 105 ++++++++++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 8 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index a67dc66b26d34..ec6b216386fbf 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -114,10 +114,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then 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 \ - pandas.core.window.rolling.Window.std \ pandas.core.window.expanding.Expanding.count \ pandas.core.window.expanding.Expanding.sum \ pandas.core.window.expanding.Expanding.mean \ diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index f4d733423b3ae..2b424d68ff7a3 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1270,7 +1270,32 @@ def aggregate(self, func, *args, **kwargs): 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([0, 1, 5, 2, 8]) + + In order to get an instance of pandas.core.window.rolling.Window we need + to pass the parameter `win_type`. + + >>> type(ser.rolling(2, win_type='gaussian')) + + + In order to use the `Sci-py` gaussian window we need to provide the parameters + M and std. The parameter M corresponds to 2 in our example. + We pass the second parameter std as a parameter of the following method + (`sum` in this case): + + >>> ser.rolling(2, win_type='gaussian').sum(std=3) + 0 NaN + 1 0.986207 + 2 5.917243 + 3 6.903450 + 4 9.862071 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="weighted window sum", agg_method="sum", @@ -1295,7 +1320,31 @@ def sum(self, numeric_only: bool = False, **kwargs): 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([0, 1, 5, 2, 8]) + + In order to get an instance of pandas.core.window.rolling.Window we need + to pass the parameter `win_type`. + + >>> type(ser.rolling(2, win_type='gaussian')) + + + In order to use the `Sci-py` gaussian window we need to provide the parameters + M and std. The parameter M corresponds to 2 in our example. + We pass the second parameter std as a parameter of the following method: + + >>> ser.rolling(2, win_type='gaussian').mean(std=3) + 0 NaN + 1 0.5 + 2 3.0 + 3 3.5 + 4 5.0 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="weighted window mean", agg_method="mean", @@ -1320,7 +1369,31 @@ def mean(self, numeric_only: bool = False, **kwargs): 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([0, 1, 5, 2, 8]) + + In order to get an instance of pandas.core.window.rolling.Window we need + to pass the parameter `win_type`. + + >>> type(ser.rolling(2, win_type='gaussian')) + + + In order to use the `Sci-py` gaussian window we need to provide the parameters + M and std. The parameter M corresponds to 2 in our example. + We pass the second parameter std as a parameter of the following method: + + >>> ser.rolling(2, win_type='gaussian').var(std=3) + 0 NaN + 1 0.5 + 2 8.0 + 3 4.5 + 4 18.0 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="weighted window variance", agg_method="var", @@ -1338,7 +1411,31 @@ def var(self, ddof: int = 1, numeric_only: bool = False, **kwargs): 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([0, 1, 5, 2, 8]) + + In order to get an instance of pandas.core.window.rolling.Window we need + to pass the parameter `win_type`. + + >>> type(ser.rolling(2, win_type='gaussian')) + + + In order to use the `Sci-py` gaussian window we need to provide the parameters + M and std. The parameter M corresponds to 2 in our example. + We pass the second parameter std as a parameter of the following method: + + >>> ser.rolling(2, win_type='gaussian').std(std=3) + 0 NaN + 1 0.707107 + 2 2.828427 + 3 2.121320 + 4 4.242641 + dtype: float64 + """ + ).replace("\n", "", 1), window_method="rolling", aggregation_description="weighted window standard deviation", agg_method="std", From d99e26077a0e98b1648de901884dddd7eb198768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 4 Jul 2023 10:12:24 +0200 Subject: [PATCH 2/5] Corrections to docstrings --- pandas/core/window/rolling.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 2b424d68ff7a3..fae83c72676a2 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1276,15 +1276,15 @@ def aggregate(self, func, *args, **kwargs): """ >>> ser = pd.Series([0, 1, 5, 2, 8]) - In order to get an instance of pandas.core.window.rolling.Window we need + To get an instance of :class: ~pandas.core.window.rolling.Window we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) - In order to use the `Sci-py` gaussian window we need to provide the parameters - M and std. The parameter M corresponds to 2 in our example. - We pass the second parameter std as a parameter of the following method + In order to use the `SciPy` Gaussian window we need to provide the parameters + `M` and `std`. The parameter `M` corresponds to 2 in our example. + We pass the second parameter `std` as a parameter of the following method (`sum` in this case): >>> ser.rolling(2, win_type='gaussian').sum(std=3) @@ -1326,15 +1326,15 @@ def sum(self, numeric_only: bool = False, **kwargs): """ >>> ser = pd.Series([0, 1, 5, 2, 8]) - In order to get an instance of pandas.core.window.rolling.Window we need + To get an instance of :class: ~pandas.core.window.rolling.Window we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) - In order to use the `Sci-py` gaussian window we need to provide the parameters - M and std. The parameter M corresponds to 2 in our example. - We pass the second parameter std as a parameter of the following method: + In order to use the `SciPy` Gaussian window we need to provide the parameters + `M` and `std`. The parameter `M` corresponds to 2 in our example. + We pass the second parameter `std` as a parameter of the following method: >>> ser.rolling(2, win_type='gaussian').mean(std=3) 0 NaN @@ -1375,15 +1375,15 @@ def mean(self, numeric_only: bool = False, **kwargs): """ >>> ser = pd.Series([0, 1, 5, 2, 8]) - In order to get an instance of pandas.core.window.rolling.Window we need + To get an instance of :class: ~pandas.core.window.rolling.Window we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) - In order to use the `Sci-py` gaussian window we need to provide the parameters - M and std. The parameter M corresponds to 2 in our example. - We pass the second parameter std as a parameter of the following method: + In order to use the `SciPy` Gaussian window we need to provide the parameters + `M` and `std`. The parameter `M` corresponds to 2 in our example. + We pass the second parameter `std` as a parameter of the following method: >>> ser.rolling(2, win_type='gaussian').var(std=3) 0 NaN @@ -1417,15 +1417,15 @@ def var(self, ddof: int = 1, numeric_only: bool = False, **kwargs): """ >>> ser = pd.Series([0, 1, 5, 2, 8]) - In order to get an instance of pandas.core.window.rolling.Window we need + To get an instance of :class: ~pandas.core.window.rolling.Window we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) - In order to use the `Sci-py` gaussian window we need to provide the parameters - M and std. The parameter M corresponds to 2 in our example. - We pass the second parameter std as a parameter of the following method: + In order to use the `SciPy` Gaussian window we need to provide the parameters + `M` and `std`. The parameter `M` corresponds to 2 in our example. + We pass the second parameter `std` as a parameter of the following method: >>> ser.rolling(2, win_type='gaussian').std(std=3) 0 NaN From adf84da486df716b4720f639c000e7e6c01abd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 4 Jul 2023 10:19:48 +0200 Subject: [PATCH 3/5] Removed replace() --- pandas/core/window/rolling.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index fae83c72676a2..5918bbc59801b 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1273,7 +1273,7 @@ def aggregate(self, func, *args, **kwargs): template_see_also, create_section_header("Examples"), dedent( - """ + """\ >>> ser = pd.Series([0, 1, 5, 2, 8]) To get an instance of :class: ~pandas.core.window.rolling.Window we need @@ -1295,7 +1295,7 @@ def aggregate(self, func, *args, **kwargs): 4 9.862071 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="weighted window sum", agg_method="sum", @@ -1323,7 +1323,7 @@ def sum(self, numeric_only: bool = False, **kwargs): template_see_also, create_section_header("Examples"), dedent( - """ + """\ >>> ser = pd.Series([0, 1, 5, 2, 8]) To get an instance of :class: ~pandas.core.window.rolling.Window we need @@ -1344,7 +1344,7 @@ def sum(self, numeric_only: bool = False, **kwargs): 4 5.0 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="weighted window mean", agg_method="mean", @@ -1414,7 +1414,7 @@ def var(self, ddof: int = 1, numeric_only: bool = False, **kwargs): template_see_also, create_section_header("Examples"), dedent( - """ + """\ >>> ser = pd.Series([0, 1, 5, 2, 8]) To get an instance of :class: ~pandas.core.window.rolling.Window we need @@ -1435,7 +1435,7 @@ def var(self, ddof: int = 1, numeric_only: bool = False, **kwargs): 4 4.242641 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="weighted window standard deviation", agg_method="std", From 4d36890cbe0fda7f2bba34fef2b00fd80ad0df0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 4 Jul 2023 16:24:31 +0200 Subject: [PATCH 4/5] Correct link take 2 --- pandas/core/window/rolling.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 5918bbc59801b..f9985d4a2ce22 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1276,7 +1276,7 @@ def aggregate(self, func, *args, **kwargs): """\ >>> ser = pd.Series([0, 1, 5, 2, 8]) - To get an instance of :class: ~pandas.core.window.rolling.Window we need + To get an instance of :class:`~pandas.core.window.rolling.Window` we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) @@ -1326,7 +1326,7 @@ def sum(self, numeric_only: bool = False, **kwargs): """\ >>> ser = pd.Series([0, 1, 5, 2, 8]) - To get an instance of :class: ~pandas.core.window.rolling.Window we need + To get an instance of :class:`~pandas.core.window.rolling.Window` we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) @@ -1375,7 +1375,7 @@ def mean(self, numeric_only: bool = False, **kwargs): """ >>> ser = pd.Series([0, 1, 5, 2, 8]) - To get an instance of :class: ~pandas.core.window.rolling.Window we need + To get an instance of :class:`~pandas.core.window.rolling.Window` we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) @@ -1417,7 +1417,7 @@ def var(self, ddof: int = 1, numeric_only: bool = False, **kwargs): """\ >>> ser = pd.Series([0, 1, 5, 2, 8]) - To get an instance of :class: ~pandas.core.window.rolling.Window we need + To get an instance of :class:`~pandas.core.window.rolling.Window` we need to pass the parameter `win_type`. >>> type(ser.rolling(2, win_type='gaussian')) From f541824808a66f1c867a91c59888cac0e865d034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 4 Jul 2023 17:22:55 +0200 Subject: [PATCH 5/5] remove replace() to right method --- pandas/core/window/rolling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index f9985d4a2ce22..47505fbbb1950 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1372,7 +1372,7 @@ def mean(self, numeric_only: bool = False, **kwargs): template_see_also, create_section_header("Examples"), dedent( - """ + """\ >>> ser = pd.Series([0, 1, 5, 2, 8]) To get an instance of :class:`~pandas.core.window.rolling.Window` we need @@ -1393,7 +1393,7 @@ def mean(self, numeric_only: bool = False, **kwargs): 4 18.0 dtype: float64 """ - ).replace("\n", "", 1), + ), window_method="rolling", aggregation_description="weighted window variance", agg_method="var",