Skip to content

Commit 1d7cab6

Browse files
authored
DOC: Fixing EX01 - Added examples (pandas-dev#53948)
* Examples Rolling.max, cov, skew, apply * correct skew * Changing format skew * Trying to fix skew * Removed replace() * Remove replace() correct doc.py links
1 parent ecc46c3 commit 1d7cab6

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-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.Rolling.max \
114-
pandas.core.window.rolling.Rolling.cov \
115-
pandas.core.window.rolling.Rolling.skew \
116-
pandas.core.window.rolling.Rolling.apply \
117113
pandas.core.window.rolling.Window.mean \
118114
pandas.core.window.rolling.Window.sum \
119115
pandas.core.window.rolling.Window.var \

pandas/core/window/rolling.py

+59-4
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,19 @@ def count(self, numeric_only: bool = False):
19001900
create_section_header("Returns"),
19011901
template_returns,
19021902
create_section_header("See Also"),
1903-
template_see_also[:-1],
1903+
template_see_also,
1904+
create_section_header("Examples"),
1905+
dedent(
1906+
"""\
1907+
>>> ser = pd.Series([1, 6, 5, 4])
1908+
>>> ser.rolling(2).apply(lambda s: s.sum() - s.min())
1909+
0 NaN
1910+
1 6.0
1911+
2 6.0
1912+
3 5.0
1913+
dtype: float64
1914+
"""
1915+
),
19041916
window_method="rolling",
19051917
aggregation_description="custom aggregation function",
19061918
agg_method="apply",
@@ -2008,7 +2020,19 @@ def sum(
20082020
create_section_header("See Also"),
20092021
template_see_also,
20102022
create_section_header("Notes"),
2011-
numba_notes[:-1],
2023+
numba_notes,
2024+
create_section_header("Examples"),
2025+
dedent(
2026+
"""\
2027+
>>> ser = pd.Series([1, 2, 3, 4])
2028+
>>> ser.rolling(2).max()
2029+
0 NaN
2030+
1 2.0
2031+
2 3.0
2032+
3 4.0
2033+
dtype: float64
2034+
"""
2035+
),
20122036
window_method="rolling",
20132037
aggregation_description="maximum",
20142038
agg_method="max",
@@ -2288,7 +2312,25 @@ def var(
22882312
"scipy.stats.skew : Third moment of a probability density.\n",
22892313
template_see_also,
22902314
create_section_header("Notes"),
2291-
"A minimum of three periods is required for the rolling calculation.\n",
2315+
dedent(
2316+
"""
2317+
A minimum of three periods is required for the rolling calculation.\n
2318+
"""
2319+
),
2320+
create_section_header("Examples"),
2321+
dedent(
2322+
"""\
2323+
>>> ser = pd.Series([1, 5, 2, 7, 12, 6])
2324+
>>> ser.rolling(3).skew().round(6)
2325+
0 NaN
2326+
1 NaN
2327+
2 1.293343
2328+
3 -0.585583
2329+
4 0.000000
2330+
5 1.545393
2331+
dtype: float64
2332+
"""
2333+
),
22922334
window_method="rolling",
22932335
aggregation_description="unbiased skewness",
22942336
agg_method="skew",
@@ -2538,7 +2580,20 @@ def rank(
25382580
create_section_header("Returns"),
25392581
template_returns,
25402582
create_section_header("See Also"),
2541-
template_see_also[:-1],
2583+
template_see_also,
2584+
create_section_header("Examples"),
2585+
dedent(
2586+
"""\
2587+
>>> ser1 = pd.Series([1, 2, 3, 4])
2588+
>>> ser2 = pd.Series([1, 4, 5, 8])
2589+
>>> ser1.rolling(2).cov(ser2)
2590+
0 NaN
2591+
1 1.5
2592+
2 0.5
2593+
3 1.5
2594+
dtype: float64
2595+
"""
2596+
),
25422597
window_method="rolling",
25432598
aggregation_description="sample covariance",
25442599
agg_method="cov",

0 commit comments

Comments
 (0)