Skip to content

DOC: Fixing EX01 - Added examples #53985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
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 \
pandas.core.window.expanding.Expanding.median \
pandas.core.window.expanding.Expanding.min \
pandas.core.window.expanding.Expanding.max \
pandas.core.window.expanding.Expanding.corr \
pandas.core.window.expanding.Expanding.cov \
pandas.core.window.expanding.Expanding.skew \
pandas.core.window.expanding.Expanding.apply \
pandas.core.window.expanding.Expanding.quantile \
pandas.core.window.ewm.ExponentialMovingWindow.mean \
pandas.core.window.ewm.ExponentialMovingWindow.sum \
pandas.core.window.ewm.ExponentialMovingWindow.std \
Expand Down
161 changes: 149 additions & 12 deletions pandas/core/window/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,19 @@ 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([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
>>> ser.expanding().count()
a 1.0
b 2.0
c 3.0
d 4.0
dtype: float64
"""
),
window_method="expanding",
aggregation_description="count of non NaN observations",
agg_method="count",
Expand All @@ -198,7 +210,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, 2, 3, 4], index=['a', 'b', 'c', 'd'])
>>> ser.expanding().apply(lambda s: s.max() - 2 * s.min())
a -1.0
b 0.0
c 1.0
d 2.0
dtype: float64
"""
),
window_method="expanding",
aggregation_description="custom aggregation function",
agg_method="apply",
Expand Down Expand Up @@ -231,7 +255,19 @@ def apply(
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], index=['a', 'b', 'c', 'd'])
>>> ser.expanding().sum()
a 1.0
b 3.0
c 6.0
d 10.0
dtype: float64
"""
),
window_method="expanding",
aggregation_description="sum",
agg_method="sum",
Expand All @@ -258,7 +294,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([3, 2, 1, 4], index=['a', 'b', 'c', 'd'])
>>> ser.expanding().max()
a 3.0
b 3.0
c 3.0
d 4.0
dtype: float64
"""
),
window_method="expanding",
aggregation_description="maximum",
agg_method="max",
Expand All @@ -285,7 +333,19 @@ def max(
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([2, 3, 4, 1], index=['a', 'b', 'c', 'd'])
>>> ser.expanding().min()
a 2.0
b 2.0
c 2.0
d 1.0
dtype: float64
"""
),
window_method="expanding",
aggregation_description="minimum",
agg_method="min",
Expand All @@ -312,7 +372,19 @@ def min(
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], index=['a', 'b', 'c', 'd'])
>>> ser.expanding().mean()
a 1.0
b 1.5
c 2.0
d 2.5
dtype: float64
"""
),
window_method="expanding",
aggregation_description="mean",
agg_method="mean",
Expand All @@ -339,7 +411,19 @@ def mean(
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], index=['a', 'b', 'c', 'd'])
>>> ser.expanding().median()
a 1.0
b 1.5
c 2.0
d 2.5
dtype: float64
"""
),
window_method="expanding",
aggregation_description="median",
agg_method="median",
Expand Down Expand Up @@ -523,7 +607,20 @@ def sem(self, ddof: int = 1, numeric_only: bool = False):
"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",
"A minimum of three periods is required for the rolling calculation.\n\n",
create_section_header("Examples"),
dedent(
"""\
>>> ser = pd.Series([-1, 0, 2, -1, 2], index=['a', 'b', 'c', 'd', 'e'])
>>> ser.expanding().skew()
a NaN
b NaN
c 0.935220
d 1.414214
e 0.315356
dtype: float64
"""
),
window_method="expanding",
aggregation_description="unbiased skewness",
agg_method="skew",
Expand Down Expand Up @@ -597,7 +694,21 @@ def kurt(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, 2, 3, 4, 5, 6], index=['a', 'b', 'c', 'd', 'e', 'f'])
>>> ser.expanding(min_periods=4).quantile(.25)
a NaN
b NaN
c NaN
d 1.75
e 2.00
f 2.25
dtype: float64
"""
),
window_method="expanding",
aggregation_description="quantile",
agg_method="quantile",
Expand Down Expand Up @@ -714,7 +825,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], index=['a', 'b', 'c', 'd'])
>>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd'])
>>> ser1.expanding().cov(ser2)
a NaN
b 0.500000
c 1.500000
d 3.333333
dtype: float64
"""
),
window_method="expanding",
aggregation_description="sample covariance",
agg_method="cov",
Expand Down Expand Up @@ -782,9 +906,22 @@ def cov(
columns on the second level.

In the case of missing elements, only complete pairwise observations
will be used.
will be used.\n
"""
).replace("\n", "", 1),
),
create_section_header("Examples"),
dedent(
"""\
>>> ser1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
>>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd'])
>>> ser1.expanding().corr(ser2)
a NaN
b 1.000000
c 0.981981
d 0.975900
dtype: float64
"""
),
window_method="expanding",
aggregation_description="correlation",
agg_method="corr",
Expand Down