Skip to content

Commit 6815db0

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#54004)
Added examples ewm
1 parent 6312cbb commit 6815db0

File tree

2 files changed

+88
-20
lines changed

2 files changed

+88
-20
lines changed

ci/code_checks.sh

-6
Original file line numberDiff line numberDiff line change
@@ -110,12 +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.ewm.ExponentialMovingWindow.mean \
114-
pandas.core.window.ewm.ExponentialMovingWindow.sum \
115-
pandas.core.window.ewm.ExponentialMovingWindow.std \
116-
pandas.core.window.ewm.ExponentialMovingWindow.var \
117-
pandas.core.window.ewm.ExponentialMovingWindow.corr \
118-
pandas.core.window.ewm.ExponentialMovingWindow.cov \
119113
pandas.api.indexers.BaseIndexer \
120114
pandas.api.indexers.VariableOffsetWindowIndexer \
121115
pandas.io.formats.style.Styler \

pandas/core/window/ewm.py

+88-14
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,19 @@ def aggregate(self, func, *args, **kwargs):
502502
create_section_header("See Also"),
503503
template_see_also,
504504
create_section_header("Notes"),
505-
numba_notes.replace("\n", "", 1),
505+
numba_notes,
506+
create_section_header("Examples"),
507+
dedent(
508+
"""\
509+
>>> ser = pd.Series([1, 2, 3, 4])
510+
>>> ser.ewm(alpha=.2).mean()
511+
0 1.000000
512+
1 1.555556
513+
2 2.147541
514+
3 2.775068
515+
dtype: float64
516+
"""
517+
),
506518
window_method="ewm",
507519
aggregation_description="(exponential weighted moment) mean",
508520
agg_method="mean",
@@ -554,7 +566,19 @@ def mean(
554566
create_section_header("See Also"),
555567
template_see_also,
556568
create_section_header("Notes"),
557-
numba_notes.replace("\n", "", 1),
569+
numba_notes,
570+
create_section_header("Examples"),
571+
dedent(
572+
"""\
573+
>>> ser = pd.Series([1, 2, 3, 4])
574+
>>> ser.ewm(alpha=.2).sum()
575+
0 1.000
576+
1 2.800
577+
2 5.240
578+
3 8.192
579+
dtype: float64
580+
"""
581+
),
558582
window_method="ewm",
559583
aggregation_description="(exponential weighted moment) sum",
560584
agg_method="sum",
@@ -602,16 +626,28 @@ def sum(
602626
template_header,
603627
create_section_header("Parameters"),
604628
dedent(
605-
"""
629+
"""\
606630
bias : bool, default False
607631
Use a standard estimation bias correction.
608632
"""
609-
).replace("\n", "", 1),
633+
),
610634
kwargs_numeric_only,
611635
create_section_header("Returns"),
612636
template_returns,
613637
create_section_header("See Also"),
614-
template_see_also[:-1],
638+
template_see_also,
639+
create_section_header("Examples"),
640+
dedent(
641+
"""\
642+
>>> ser = pd.Series([1, 2, 3, 4])
643+
>>> ser.ewm(alpha=.2).std()
644+
0 NaN
645+
1 0.707107
646+
2 0.995893
647+
3 1.277320
648+
dtype: float64
649+
"""
650+
),
615651
window_method="ewm",
616652
aggregation_description="(exponential weighted moment) standard deviation",
617653
agg_method="std",
@@ -632,16 +668,28 @@ def std(self, bias: bool = False, numeric_only: bool = False):
632668
template_header,
633669
create_section_header("Parameters"),
634670
dedent(
635-
"""
671+
"""\
636672
bias : bool, default False
637673
Use a standard estimation bias correction.
638674
"""
639-
).replace("\n", "", 1),
675+
),
640676
kwargs_numeric_only,
641677
create_section_header("Returns"),
642678
template_returns,
643679
create_section_header("See Also"),
644-
template_see_also[:-1],
680+
template_see_also,
681+
create_section_header("Examples"),
682+
dedent(
683+
"""\
684+
>>> ser = pd.Series([1, 2, 3, 4])
685+
>>> ser.ewm(alpha=.2).var()
686+
0 NaN
687+
1 0.500000
688+
2 0.991803
689+
3 1.631547
690+
dtype: float64
691+
"""
692+
),
645693
window_method="ewm",
646694
aggregation_description="(exponential weighted moment) variance",
647695
agg_method="var",
@@ -665,7 +713,7 @@ def var_func(values, begin, end, min_periods):
665713
template_header,
666714
create_section_header("Parameters"),
667715
dedent(
668-
"""
716+
"""\
669717
other : Series or DataFrame , optional
670718
If not supplied then will default to self and produce pairwise
671719
output.
@@ -679,12 +727,25 @@ def var_func(values, begin, end, min_periods):
679727
bias : bool, default False
680728
Use a standard estimation bias correction.
681729
"""
682-
).replace("\n", "", 1),
730+
),
683731
kwargs_numeric_only,
684732
create_section_header("Returns"),
685733
template_returns,
686734
create_section_header("See Also"),
687-
template_see_also[:-1],
735+
template_see_also,
736+
create_section_header("Examples"),
737+
dedent(
738+
"""\
739+
>>> ser1 = pd.Series([1, 2, 3, 4])
740+
>>> ser2 = pd.Series([10, 11, 13, 16])
741+
>>> ser1.ewm(alpha=.2).cov(ser2)
742+
0 NaN
743+
1 0.500000
744+
2 1.524590
745+
3 3.408836
746+
dtype: float64
747+
"""
748+
),
688749
window_method="ewm",
689750
aggregation_description="(exponential weighted moment) sample covariance",
690751
agg_method="cov",
@@ -739,7 +800,7 @@ def cov_func(x, y):
739800
template_header,
740801
create_section_header("Parameters"),
741802
dedent(
742-
"""
803+
"""\
743804
other : Series or DataFrame, optional
744805
If not supplied then will default to self and produce pairwise
745806
output.
@@ -751,12 +812,25 @@ def cov_func(x, y):
751812
inputs. In the case of missing elements, only complete pairwise
752813
observations will be used.
753814
"""
754-
).replace("\n", "", 1),
815+
),
755816
kwargs_numeric_only,
756817
create_section_header("Returns"),
757818
template_returns,
758819
create_section_header("See Also"),
759-
template_see_also[:-1],
820+
template_see_also,
821+
create_section_header("Examples"),
822+
dedent(
823+
"""\
824+
>>> ser1 = pd.Series([1, 2, 3, 4])
825+
>>> ser2 = pd.Series([10, 11, 13, 16])
826+
>>> ser1.ewm(alpha=.2).corr(ser2)
827+
0 NaN
828+
1 1.000000
829+
2 0.982821
830+
3 0.977802
831+
dtype: float64
832+
"""
833+
),
760834
window_method="ewm",
761835
aggregation_description="(exponential weighted moment) sample correlation",
762836
agg_method="corr",

0 commit comments

Comments
 (0)