Skip to content

Commit 172b7c1

Browse files
authored
DOC: Fixing EX01 - Added examples (pandas-dev#53982)
* Examples Window.mean, sum, var, std * Corrections to docstrings * Removed replace() * Correct link take 2 * remove replace() to right method
1 parent bcb3fa8 commit 172b7c1

File tree

2 files changed

+101
-8
lines changed

2 files changed

+101
-8
lines changed

ci/code_checks.sh

-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
110110
pandas_object \
111111
pandas.api.interchange.from_dataframe \
112112
pandas.DatetimeIndex.snap \
113-
pandas.core.window.rolling.Window.mean \
114-
pandas.core.window.rolling.Window.sum \
115-
pandas.core.window.rolling.Window.var \
116-
pandas.core.window.rolling.Window.std \
117113
pandas.core.window.ewm.ExponentialMovingWindow.mean \
118114
pandas.core.window.ewm.ExponentialMovingWindow.sum \
119115
pandas.core.window.ewm.ExponentialMovingWindow.std \

pandas/core/window/rolling.py

+101-4
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,32 @@ def aggregate(self, func, *args, **kwargs):
12701270
create_section_header("Returns"),
12711271
template_returns,
12721272
create_section_header("See Also"),
1273-
template_see_also[:-1],
1273+
template_see_also,
1274+
create_section_header("Examples"),
1275+
dedent(
1276+
"""\
1277+
>>> ser = pd.Series([0, 1, 5, 2, 8])
1278+
1279+
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
1280+
to pass the parameter `win_type`.
1281+
1282+
>>> type(ser.rolling(2, win_type='gaussian'))
1283+
<class 'pandas.core.window.rolling.Window'>
1284+
1285+
In order to use the `SciPy` Gaussian window we need to provide the parameters
1286+
`M` and `std`. The parameter `M` corresponds to 2 in our example.
1287+
We pass the second parameter `std` as a parameter of the following method
1288+
(`sum` in this case):
1289+
1290+
>>> ser.rolling(2, win_type='gaussian').sum(std=3)
1291+
0 NaN
1292+
1 0.986207
1293+
2 5.917243
1294+
3 6.903450
1295+
4 9.862071
1296+
dtype: float64
1297+
"""
1298+
),
12741299
window_method="rolling",
12751300
aggregation_description="weighted window sum",
12761301
agg_method="sum",
@@ -1295,7 +1320,31 @@ def sum(self, numeric_only: bool = False, **kwargs):
12951320
create_section_header("Returns"),
12961321
template_returns,
12971322
create_section_header("See Also"),
1298-
template_see_also[:-1],
1323+
template_see_also,
1324+
create_section_header("Examples"),
1325+
dedent(
1326+
"""\
1327+
>>> ser = pd.Series([0, 1, 5, 2, 8])
1328+
1329+
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
1330+
to pass the parameter `win_type`.
1331+
1332+
>>> type(ser.rolling(2, win_type='gaussian'))
1333+
<class 'pandas.core.window.rolling.Window'>
1334+
1335+
In order to use the `SciPy` Gaussian window we need to provide the parameters
1336+
`M` and `std`. The parameter `M` corresponds to 2 in our example.
1337+
We pass the second parameter `std` as a parameter of the following method:
1338+
1339+
>>> ser.rolling(2, win_type='gaussian').mean(std=3)
1340+
0 NaN
1341+
1 0.5
1342+
2 3.0
1343+
3 3.5
1344+
4 5.0
1345+
dtype: float64
1346+
"""
1347+
),
12991348
window_method="rolling",
13001349
aggregation_description="weighted window mean",
13011350
agg_method="mean",
@@ -1320,7 +1369,31 @@ def mean(self, numeric_only: bool = False, **kwargs):
13201369
create_section_header("Returns"),
13211370
template_returns,
13221371
create_section_header("See Also"),
1323-
template_see_also[:-1],
1372+
template_see_also,
1373+
create_section_header("Examples"),
1374+
dedent(
1375+
"""\
1376+
>>> ser = pd.Series([0, 1, 5, 2, 8])
1377+
1378+
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
1379+
to pass the parameter `win_type`.
1380+
1381+
>>> type(ser.rolling(2, win_type='gaussian'))
1382+
<class 'pandas.core.window.rolling.Window'>
1383+
1384+
In order to use the `SciPy` Gaussian window we need to provide the parameters
1385+
`M` and `std`. The parameter `M` corresponds to 2 in our example.
1386+
We pass the second parameter `std` as a parameter of the following method:
1387+
1388+
>>> ser.rolling(2, win_type='gaussian').var(std=3)
1389+
0 NaN
1390+
1 0.5
1391+
2 8.0
1392+
3 4.5
1393+
4 18.0
1394+
dtype: float64
1395+
"""
1396+
),
13241397
window_method="rolling",
13251398
aggregation_description="weighted window variance",
13261399
agg_method="var",
@@ -1338,7 +1411,31 @@ def var(self, ddof: int = 1, numeric_only: bool = False, **kwargs):
13381411
create_section_header("Returns"),
13391412
template_returns,
13401413
create_section_header("See Also"),
1341-
template_see_also[:-1],
1414+
template_see_also,
1415+
create_section_header("Examples"),
1416+
dedent(
1417+
"""\
1418+
>>> ser = pd.Series([0, 1, 5, 2, 8])
1419+
1420+
To get an instance of :class:`~pandas.core.window.rolling.Window` we need
1421+
to pass the parameter `win_type`.
1422+
1423+
>>> type(ser.rolling(2, win_type='gaussian'))
1424+
<class 'pandas.core.window.rolling.Window'>
1425+
1426+
In order to use the `SciPy` Gaussian window we need to provide the parameters
1427+
`M` and `std`. The parameter `M` corresponds to 2 in our example.
1428+
We pass the second parameter `std` as a parameter of the following method:
1429+
1430+
>>> ser.rolling(2, win_type='gaussian').std(std=3)
1431+
0 NaN
1432+
1 0.707107
1433+
2 2.828427
1434+
3 2.121320
1435+
4 4.242641
1436+
dtype: float64
1437+
"""
1438+
),
13421439
window_method="rolling",
13431440
aggregation_description="weighted window standard deviation",
13441441
agg_method="std",

0 commit comments

Comments
 (0)