Skip to content

Commit 8eb1048

Browse files
KrishnaSai2020KrishnaSai2020charlesdong1991
authored
DOC: explain EWM (#34910)
* fixed issue #34867 * pep8: line too long * Update pandas/core/generic.py Co-authored-by: Kaiqi Dong <[email protected]> * fixed issue #34867 * fixed issue #34867 * fixed pep8 issue * renamed exponentialmoving back to ewm.py * pep 8 issues * pep 8 issues Co-authored-by: KrishnaSai2020 <[email protected]> Co-authored-by: Kaiqi Dong <[email protected]>
1 parent 9114b4b commit 8eb1048

File tree

9 files changed

+37
-32
lines changed

9 files changed

+37
-32
lines changed

doc/redirects.csv

+5-5
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ generated/pandas.core.resample.Resampler.std,../reference/api/pandas.core.resamp
269269
generated/pandas.core.resample.Resampler.sum,../reference/api/pandas.core.resample.Resampler.sum
270270
generated/pandas.core.resample.Resampler.transform,../reference/api/pandas.core.resample.Resampler.transform
271271
generated/pandas.core.resample.Resampler.var,../reference/api/pandas.core.resample.Resampler.var
272-
generated/pandas.core.window.EWM.corr,../reference/api/pandas.core.window.EWM.corr
273-
generated/pandas.core.window.EWM.cov,../reference/api/pandas.core.window.EWM.cov
274-
generated/pandas.core.window.EWM.mean,../reference/api/pandas.core.window.EWM.mean
275-
generated/pandas.core.window.EWM.std,../reference/api/pandas.core.window.EWM.std
276-
generated/pandas.core.window.EWM.var,../reference/api/pandas.core.window.EWM.var
272+
generated/pandas.core.window.ExponentialMovingWindow.corr,../reference/api/pandas.core.window.ExponentialMovingWindow.corr
273+
generated/pandas.core.window.ExponentialMovingWindow.cov,../reference/api/pandas.core.window.ExponentialMovingWindow.cov
274+
generated/pandas.core.window.ExponentialMovingWindow.mean,../reference/api/pandas.core.window.ExponentialMovingWindow.mean
275+
generated/pandas.core.window.ExponentialMovingWindow.std,../reference/api/pandas.core.window.ExponentialMovingWindow.std
276+
generated/pandas.core.window.ExponentialMovingWindow.var,../reference/api/pandas.core.window.ExponentialMovingWindow.var
277277
generated/pandas.core.window.Expanding.aggregate,../reference/api/pandas.core.window.Expanding.aggregate
278278
generated/pandas.core.window.Expanding.apply,../reference/api/pandas.core.window.Expanding.apply
279279
generated/pandas.core.window.Expanding.corr,../reference/api/pandas.core.window.Expanding.corr

doc/source/reference/window.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Window
88

99
Rolling objects are returned by ``.rolling`` calls: :func:`pandas.DataFrame.rolling`, :func:`pandas.Series.rolling`, etc.
1010
Expanding objects are returned by ``.expanding`` calls: :func:`pandas.DataFrame.expanding`, :func:`pandas.Series.expanding`, etc.
11-
EWM objects are returned by ``.ewm`` calls: :func:`pandas.DataFrame.ewm`, :func:`pandas.Series.ewm`, etc.
11+
ExponentialMovingWindow objects are returned by ``.ewm`` calls: :func:`pandas.DataFrame.ewm`, :func:`pandas.Series.ewm`, etc.
1212

1313
Standard moving window functions
1414
--------------------------------
@@ -69,11 +69,11 @@ Exponentially-weighted moving window functions
6969
.. autosummary::
7070
:toctree: api/
7171

72-
EWM.mean
73-
EWM.std
74-
EWM.var
75-
EWM.corr
76-
EWM.cov
72+
ExponentialMovingWindow.mean
73+
ExponentialMovingWindow.std
74+
ExponentialMovingWindow.var
75+
ExponentialMovingWindow.corr
76+
ExponentialMovingWindow.cov
7777

7878
Window indexer
7979
--------------

doc/source/user_guide/computation.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ see the :ref:`groupby docs <groupby.transform.window_resample>`.
230230
The API for window statistics is quite similar to the way one works with ``GroupBy`` objects, see the documentation :ref:`here <groupby>`.
231231

232232
We work with ``rolling``, ``expanding`` and ``exponentially weighted`` data through the corresponding
233-
objects, :class:`~pandas.core.window.Rolling`, :class:`~pandas.core.window.Expanding` and :class:`~pandas.core.window.EWM`.
233+
objects, :class:`~pandas.core.window.Rolling`, :class:`~pandas.core.window.Expanding` and :class:`~pandas.core.window.ExponentialMovingWindow`.
234234

235235
.. ipython:: python
236236
@@ -777,7 +777,7 @@ columns by reshaping and indexing:
777777
Aggregation
778778
-----------
779779

780-
Once the ``Rolling``, ``Expanding`` or ``EWM`` objects have been created, several methods are available to
780+
Once the ``Rolling``, ``Expanding`` or ``ExponentialMovingWindow`` objects have been created, several methods are available to
781781
perform multiple computations on the data. These operations are similar to the :ref:`aggregating API <basics.aggregate>`,
782782
:ref:`groupby API <groupby.aggregate>`, and :ref:`resample API <timeseries.aggregate>`.
783783

@@ -971,7 +971,7 @@ Exponentially weighted windows
971971

972972
A related set of functions are exponentially weighted versions of several of
973973
the above statistics. A similar interface to ``.rolling`` and ``.expanding`` is accessed
974-
through the ``.ewm`` method to receive an :class:`~EWM` object.
974+
through the ``.ewm`` method to receive an :class:`~ExponentialMovingWindow` object.
975975
A number of expanding EW (exponentially weighted)
976976
methods are provided:
977977

@@ -980,11 +980,11 @@ methods are provided:
980980
:header: "Function", "Description"
981981
:widths: 20, 80
982982

983-
:meth:`~EWM.mean`, EW moving average
984-
:meth:`~EWM.var`, EW moving variance
985-
:meth:`~EWM.std`, EW moving standard deviation
986-
:meth:`~EWM.corr`, EW moving correlation
987-
:meth:`~EWM.cov`, EW moving covariance
983+
:meth:`~ExponentialMovingWindow.mean`, EW moving average
984+
:meth:`~ExponentialMovingWindow.var`, EW moving variance
985+
:meth:`~ExponentialMovingWindow.std`, EW moving standard deviation
986+
:meth:`~ExponentialMovingWindow.corr`, EW moving correlation
987+
:meth:`~ExponentialMovingWindow.cov`, EW moving covariance
988988

989989
In general, a weighted moving average is calculated as
990990

@@ -1090,12 +1090,12 @@ Here is an example for a univariate time series:
10901090
@savefig ewma_ex.png
10911091
s.ewm(span=20).mean().plot(style='k')
10921092
1093-
EWM has a ``min_periods`` argument, which has the same
1093+
ExponentialMovingWindow has a ``min_periods`` argument, which has the same
10941094
meaning it does for all the ``.expanding`` and ``.rolling`` methods:
10951095
no output values will be set until at least ``min_periods`` non-null values
10961096
are encountered in the (expanding) window.
10971097

1098-
EWM also has an ``ignore_na`` argument, which determines how
1098+
ExponentialMovingWindow also has an ``ignore_na`` argument, which determines how
10991099
intermediate null values affect the calculation of the weights.
11001100
When ``ignore_na=False`` (the default), weights are calculated based on absolute
11011101
positions, so that intermediate null values affect the result.

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ Groupby/resample/rolling
12061206
- Bug in :meth:`pandas.core.groupby.GroupBy.agg` where incorrect results are returned for uint64 columns. (:issue:`26310`)
12071207
- Bug in :meth:`pandas.core.window.Rolling.median` and :meth:`pandas.core.window.Rolling.quantile` where MemoryError is raised with empty window (:issue:`26005`)
12081208
- Bug in :meth:`pandas.core.window.Rolling.median` and :meth:`pandas.core.window.Rolling.quantile` where incorrect results are returned with ``closed='left'`` and ``closed='neither'`` (:issue:`26005`)
1209-
- Improved :class:`pandas.core.window.Rolling`, :class:`pandas.core.window.Window` and :class:`pandas.core.window.EWM` functions to exclude nuisance columns from results instead of raising errors and raise a ``DataError`` only if all columns are nuisance (:issue:`12537`)
1209+
- Improved :class:`pandas.core.window.Rolling`, :class:`pandas.core.window.Window` and :class:`pandas.core.window.ExponentialMovingWindow` functions to exclude nuisance columns from results instead of raising errors and raise a ``DataError`` only if all columns are nuisance (:issue:`12537`)
12101210
- Bug in :meth:`pandas.core.window.Rolling.max` and :meth:`pandas.core.window.Rolling.min` where incorrect results are returned with an empty variable window (:issue:`26005`)
12111211
- Raise a helpful exception when an unsupported weighted window function is used as an argument of :meth:`pandas.core.window.Window.aggregate` (:issue:`26597`)
12121212

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7288,7 +7288,7 @@ def _gotitem(
72887288
core.resample.Resampler : Perform operations over resampled bins.
72897289
core.window.Rolling : Perform operations over rolling window.
72907290
core.window.Expanding : Perform operations over expanding window.
7291-
core.window.EWM : Perform operation over exponential weighted
7291+
core.window.ExponentialMovingWindow : Perform operation over exponential weighted
72927292
window.
72937293
"""
72947294
)
@@ -8171,7 +8171,7 @@ def cov(self, min_periods=None) -> "DataFrame":
81718171
See Also
81728172
--------
81738173
Series.cov : Compute covariance with another Series.
8174-
core.window.EWM.cov: Exponential weighted sample covariance.
8174+
core.window.ExponentialMovingWindow.cov: Exponential weighted sample covariance.
81758175
core.window.Expanding.cov : Expanding sample covariance.
81768176
core.window.Rolling.cov : Rolling sample covariance.
81778177

pandas/core/generic.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10460,7 +10460,12 @@ def _add_series_or_dataframe_operations(cls):
1046010460
Add the series or dataframe only operations to the cls; evaluate
1046110461
the doc strings again.
1046210462
"""
10463-
from pandas.core.window import EWM, Expanding, Rolling, Window
10463+
from pandas.core.window import (
10464+
Expanding,
10465+
ExponentialMovingWindow,
10466+
Rolling,
10467+
Window,
10468+
)
1046410469

1046510470
@doc(Rolling)
1046610471
def rolling(
@@ -10507,7 +10512,7 @@ def expanding(self, min_periods=1, center=False, axis=0):
1050710512

1050810513
cls.expanding = expanding
1050910514

10510-
@doc(EWM)
10515+
@doc(ExponentialMovingWindow)
1051110516
def ewm(
1051210517
self,
1051310518
com=None,
@@ -10520,7 +10525,7 @@ def ewm(
1052010525
axis=0,
1052110526
):
1052210527
axis = self._get_axis_number(axis)
10523-
return EWM(
10528+
return ExponentialMovingWindow(
1052410529
self,
1052510530
com=com,
1052610531
span=span,

pandas/core/window/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from pandas.core.window.ewm import EWM # noqa:F401
1+
from pandas.core.window.ewm import ExponentialMovingWindow # noqa:F401
22
from pandas.core.window.expanding import Expanding, ExpandingGroupby # noqa:F401
33
from pandas.core.window.rolling import Rolling, RollingGroupby, Window # noqa:F401

pandas/core/window/ewm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_center_of_mass(
5959
return float(comass)
6060

6161

62-
class EWM(_Rolling):
62+
class ExponentialMovingWindow(_Rolling):
6363
r"""
6464
Provide exponential weighted (EW) functions.
6565
@@ -185,7 +185,7 @@ def __init__(
185185

186186
@property
187187
def _constructor(self):
188-
return EWM
188+
return ExponentialMovingWindow
189189

190190
_agg_see_also_doc = dedent(
191191
"""

pandas/tests/window/test_ewm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pandas.errors import UnsupportedFunctionCall
55

66
from pandas import DataFrame, Series
7-
from pandas.core.window import EWM
7+
from pandas.core.window import ExponentialMovingWindow
88

99

1010
def test_doc_string():
@@ -56,7 +56,7 @@ def test_constructor(which):
5656
@pytest.mark.parametrize("method", ["std", "mean", "var"])
5757
def test_numpy_compat(method):
5858
# see gh-12811
59-
e = EWM(Series([2, 4, 6]), alpha=0.5)
59+
e = ExponentialMovingWindow(Series([2, 4, 6]), alpha=0.5)
6060

6161
msg = "numpy operations are not valid with window objects"
6262

0 commit comments

Comments
 (0)