diff --git a/doc/redirects.csv b/doc/redirects.csv index b59ccf649ee21..bceb4b5961324 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -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 diff --git a/doc/source/reference/window.rst b/doc/source/reference/window.rst index fb60a0d387ca2..d7e6405a3732b 100644 --- a/doc/source/reference/window.rst +++ b/doc/source/reference/window.rst @@ -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 -------------------------------- @@ -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 -------------- diff --git a/doc/source/user_guide/computation.rst b/doc/source/user_guide/computation.rst index cf630a9671013..19fdb541a6a45 100644 --- a/doc/source/user_guide/computation.rst +++ b/doc/source/user_guide/computation.rst @@ -230,7 +230,7 @@ see the :ref:`groupby docs `. The API for window statistics is quite similar to the way one works with ``GroupBy`` objects, see the documentation :ref:`here `. 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 @@ -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 `, :ref:`groupby API `, and :ref:`resample API `. @@ -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: @@ -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 @@ -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. diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 44558fd63ba15..3cd920158f774 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -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`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 39ca7ed47f7fa..d12ebeafe8510 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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. """ ) @@ -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. diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 701909c9df857..1404d225eea97 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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( @@ -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, @@ -10520,7 +10525,7 @@ def ewm( axis=0, ): axis = self._get_axis_number(axis) - return EWM( + return ExponentialMovingWindow( self, com=com, span=span, diff --git a/pandas/core/window/__init__.py b/pandas/core/window/__init__.py index dcf58a4c0dd5b..304c61ac0e489 100644 --- a/pandas/core/window/__init__.py +++ b/pandas/core/window/__init__.py @@ -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 diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index b708020be90d2..ee80f80b320e4 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -59,7 +59,7 @@ def get_center_of_mass( return float(comass) -class EWM(_Rolling): +class ExponentialMovingWindow(_Rolling): r""" Provide exponential weighted (EW) functions. @@ -185,7 +185,7 @@ def __init__( @property def _constructor(self): - return EWM + return ExponentialMovingWindow _agg_see_also_doc = dedent( """ diff --git a/pandas/tests/window/test_ewm.py b/pandas/tests/window/test_ewm.py index 9ba194dcf0959..0957cac7aff95 100644 --- a/pandas/tests/window/test_ewm.py +++ b/pandas/tests/window/test_ewm.py @@ -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(): @@ -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"