Skip to content

DOC: explain EWM #34910

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 9 commits into from
Jun 20, 2020
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
10 changes: 5 additions & 5 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ generated/pandas.core.resample.Resampler.std,../reference/api/pandas.core.resamp
generated/pandas.core.resample.Resampler.sum,../reference/api/pandas.core.resample.Resampler.sum
generated/pandas.core.resample.Resampler.transform,../reference/api/pandas.core.resample.Resampler.transform
generated/pandas.core.resample.Resampler.var,../reference/api/pandas.core.resample.Resampler.var
generated/pandas.core.window.EWM.corr,../reference/api/pandas.core.window.EWM.corr
generated/pandas.core.window.EWM.cov,../reference/api/pandas.core.window.EWM.cov
generated/pandas.core.window.EWM.mean,../reference/api/pandas.core.window.EWM.mean
generated/pandas.core.window.EWM.std,../reference/api/pandas.core.window.EWM.std
generated/pandas.core.window.EWM.var,../reference/api/pandas.core.window.EWM.var
generated/pandas.core.window.ExponentialMovingWindow.corr,../reference/api/pandas.core.window.ExponentialMovingWindow.corr
generated/pandas.core.window.ExponentialMovingWindow.cov,../reference/api/pandas.core.window.ExponentialMovingWindow.cov
generated/pandas.core.window.ExponentialMovingWindow.mean,../reference/api/pandas.core.window.ExponentialMovingWindow.mean
generated/pandas.core.window.ExponentialMovingWindow.std,../reference/api/pandas.core.window.ExponentialMovingWindow.std
generated/pandas.core.window.ExponentialMovingWindow.var,../reference/api/pandas.core.window.ExponentialMovingWindow.var
generated/pandas.core.window.Expanding.aggregate,../reference/api/pandas.core.window.Expanding.aggregate
generated/pandas.core.window.Expanding.apply,../reference/api/pandas.core.window.Expanding.apply
generated/pandas.core.window.Expanding.corr,../reference/api/pandas.core.window.Expanding.corr
Expand Down
12 changes: 6 additions & 6 deletions doc/source/reference/window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Window

Rolling objects are returned by ``.rolling`` calls: :func:`pandas.DataFrame.rolling`, :func:`pandas.Series.rolling`, etc.
Expanding objects are returned by ``.expanding`` calls: :func:`pandas.DataFrame.expanding`, :func:`pandas.Series.expanding`, etc.
EWM objects are returned by ``.ewm`` calls: :func:`pandas.DataFrame.ewm`, :func:`pandas.Series.ewm`, etc.
ExponentialMovingWindow objects are returned by ``.ewm`` calls: :func:`pandas.DataFrame.ewm`, :func:`pandas.Series.ewm`, etc.

Standard moving window functions
--------------------------------
Expand Down Expand Up @@ -69,11 +69,11 @@ Exponentially-weighted moving window functions
.. autosummary::
:toctree: api/

EWM.mean
EWM.std
EWM.var
EWM.corr
EWM.cov
ExponentialMovingWindow.mean
ExponentialMovingWindow.std
ExponentialMovingWindow.var
ExponentialMovingWindow.corr
ExponentialMovingWindow.cov

Window indexer
--------------
Expand Down
20 changes: 10 additions & 10 deletions doc/source/user_guide/computation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ see the :ref:`groupby docs <groupby.transform.window_resample>`.
The API for window statistics is quite similar to the way one works with ``GroupBy`` objects, see the documentation :ref:`here <groupby>`.

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

.. ipython:: python

Expand Down Expand Up @@ -777,7 +777,7 @@ columns by reshaping and indexing:
Aggregation
-----------

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

Expand Down Expand Up @@ -971,7 +971,7 @@ Exponentially weighted windows

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

Expand All @@ -980,11 +980,11 @@ methods are provided:
:header: "Function", "Description"
:widths: 20, 80

:meth:`~EWM.mean`, EW moving average
:meth:`~EWM.var`, EW moving variance
:meth:`~EWM.std`, EW moving standard deviation
:meth:`~EWM.corr`, EW moving correlation
:meth:`~EWM.cov`, EW moving covariance
:meth:`~ExponentialMovingWindow.mean`, EW moving average
:meth:`~ExponentialMovingWindow.var`, EW moving variance
:meth:`~ExponentialMovingWindow.std`, EW moving standard deviation
:meth:`~ExponentialMovingWindow.corr`, EW moving correlation
:meth:`~ExponentialMovingWindow.cov`, EW moving covariance

In general, a weighted moving average is calculated as

Expand Down Expand Up @@ -1090,12 +1090,12 @@ Here is an example for a univariate time series:
@savefig ewma_ex.png
s.ewm(span=20).mean().plot(style='k')

EWM has a ``min_periods`` argument, which has the same
ExponentialMovingWindow has a ``min_periods`` argument, which has the same
meaning it does for all the ``.expanding`` and ``.rolling`` methods:
no output values will be set until at least ``min_periods`` non-null values
are encountered in the (expanding) window.

EWM also has an ``ignore_na`` argument, which determines how
ExponentialMovingWindow also has an ``ignore_na`` argument, which determines how
intermediate null values affect the calculation of the weights.
When ``ignore_na=False`` (the default), weights are calculated based on absolute
positions, so that intermediate null values affect the result.
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ Groupby/resample/rolling
- Bug in :meth:`pandas.core.groupby.GroupBy.agg` where incorrect results are returned for uint64 columns. (:issue:`26310`)
- Bug in :meth:`pandas.core.window.Rolling.median` and :meth:`pandas.core.window.Rolling.quantile` where MemoryError is raised with empty window (:issue:`26005`)
- 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`)
- 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`)
- 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`)
- 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`)
- Raise a helpful exception when an unsupported weighted window function is used as an argument of :meth:`pandas.core.window.Window.aggregate` (:issue:`26597`)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7288,7 +7288,7 @@ def _gotitem(
core.resample.Resampler : Perform operations over resampled bins.
core.window.Rolling : Perform operations over rolling window.
core.window.Expanding : Perform operations over expanding window.
core.window.EWM : Perform operation over exponential weighted
core.window.ExponentialMovingWindow : Perform operation over exponential weighted
window.
"""
)
Expand Down Expand Up @@ -8171,7 +8171,7 @@ def cov(self, min_periods=None) -> "DataFrame":
See Also
--------
Series.cov : Compute covariance with another Series.
core.window.EWM.cov: Exponential weighted sample covariance.
core.window.ExponentialMovingWindow.cov: Exponential weighted sample covariance.
core.window.Expanding.cov : Expanding sample covariance.
core.window.Rolling.cov : Rolling sample covariance.

Expand Down
11 changes: 8 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10460,7 +10460,12 @@ def _add_series_or_dataframe_operations(cls):
Add the series or dataframe only operations to the cls; evaluate
the doc strings again.
"""
from pandas.core.window import EWM, Expanding, Rolling, Window
from pandas.core.window import (
Expanding,
ExponentialMovingWindow,
Rolling,
Window,
)

@doc(Rolling)
def rolling(
Expand Down Expand Up @@ -10507,7 +10512,7 @@ def expanding(self, min_periods=1, center=False, axis=0):

cls.expanding = expanding

@doc(EWM)
@doc(ExponentialMovingWindow)
def ewm(
self,
com=None,
Expand All @@ -10520,7 +10525,7 @@ def ewm(
axis=0,
):
axis = self._get_axis_number(axis)
return EWM(
return ExponentialMovingWindow(
self,
com=com,
span=span,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from pandas.core.window.ewm import EWM # noqa:F401
from pandas.core.window.ewm import ExponentialMovingWindow # noqa:F401
from pandas.core.window.expanding import Expanding, ExpandingGroupby # noqa:F401
from pandas.core.window.rolling import Rolling, RollingGroupby, Window # noqa:F401
4 changes: 2 additions & 2 deletions pandas/core/window/ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_center_of_mass(
return float(comass)


class EWM(_Rolling):
class ExponentialMovingWindow(_Rolling):
r"""
Provide exponential weighted (EW) functions.

Expand Down Expand Up @@ -185,7 +185,7 @@ def __init__(

@property
def _constructor(self):
return EWM
return ExponentialMovingWindow

_agg_see_also_doc = dedent(
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/window/test_ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pandas.errors import UnsupportedFunctionCall

from pandas import DataFrame, Series
from pandas.core.window import EWM
from pandas.core.window import ExponentialMovingWindow


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

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

Expand Down