From 3f9f23b69b08aa51bf8269c36b62143f0a779872 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sat, 20 Jun 2020 18:18:59 +0100 Subject: [PATCH 1/9] fixed issue #34867 --- pandas/core/generic.py | 6 +++--- pandas/core/window/__init__.py | 2 +- pandas/core/window/{ewm.py => exponentialmovingwindow.py} | 4 ++-- pandas/tests/window/test_ewm.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) rename pandas/core/window/{ewm.py => exponentialmovingwindow.py} (99%) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 701909c9df857..513e8b7de659e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10460,7 +10460,7 @@ 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 ExponentialMovingWindow, Expanding, Rolling, Window @doc(Rolling) def rolling( @@ -10507,7 +10507,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 +10520,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..e4ecdf0011f7e 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.exponentialmovingwindow 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/exponentialmovingwindow.py similarity index 99% rename from pandas/core/window/ewm.py rename to pandas/core/window/exponentialmovingwindow.py index b708020be90d2..ee80f80b320e4 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/exponentialmovingwindow.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" From 97843037568465d463bc44271cf21033dcecfb45 Mon Sep 17 00:00:00 2001 From: Krishna Chivukula <63070026+KrishnaSai2020@users.noreply.github.com> Date: Sat, 20 Jun 2020 18:23:47 +0100 Subject: [PATCH 2/9] pep8: line too long --- pandas/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 513e8b7de659e..2370577699db9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10460,7 +10460,8 @@ 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 ExponentialMovingWindow, Expanding, Rolling, Window + from pandas.core.window import ExponentialMovingWindow, Expanding, Rolling + from pandas.core.window import Window @doc(Rolling) def rolling( From 59580b7d989adf577671ad69910ce305d91a45bd Mon Sep 17 00:00:00 2001 From: Krishna Chivukula <63070026+KrishnaSai2020@users.noreply.github.com> Date: Sat, 20 Jun 2020 18:42:11 +0100 Subject: [PATCH 3/9] Update pandas/core/generic.py Co-authored-by: Kaiqi Dong --- pandas/core/generic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2370577699db9..697e30f5a3666 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10460,8 +10460,7 @@ 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 ExponentialMovingWindow, Expanding, Rolling - from pandas.core.window import Window + from pandas.core.window import Expanding, ExponentialMovingWindow, Rolling, Window @doc(Rolling) def rolling( From 07755a0bca8162ab3fcf3dd5e9a019caa09356fb Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sat, 20 Jun 2020 18:46:50 +0100 Subject: [PATCH 4/9] fixed issue #34867 --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 697e30f5a3666..0bf551657070c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10460,7 +10460,7 @@ 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 Expanding, ExponentialMovingWindow, Rolling, Window + from .window import Expanding, ExponentialMovingWindow, Rolling, Window @doc(Rolling) def rolling( From bb84b89953e6afcd8c6be4a3abe58dcd8ef4ce03 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sat, 20 Jun 2020 19:01:55 +0100 Subject: [PATCH 5/9] fixed issue #34867 --- pandas/core/generic.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0bf551657070c..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 .window import Expanding, ExponentialMovingWindow, Rolling, Window + from pandas.core.window import ( + Expanding, + ExponentialMovingWindow, + Rolling, + Window, + ) @doc(Rolling) def rolling( From 70498be93d1ff20ce94f8546c03d34e94c024532 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sat, 20 Jun 2020 19:22:06 +0100 Subject: [PATCH 6/9] fixed pep8 issue --- pandas/core/window/__init__.py | 2 +- .../window/{exponentialmovingwindow.py => exponentialmoving.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename pandas/core/window/{exponentialmovingwindow.py => exponentialmoving.py} (100%) diff --git a/pandas/core/window/__init__.py b/pandas/core/window/__init__.py index e4ecdf0011f7e..68773b3fcc651 100644 --- a/pandas/core/window/__init__.py +++ b/pandas/core/window/__init__.py @@ -1,3 +1,3 @@ -from pandas.core.window.exponentialmovingwindow import ExponentialMovingWindow # noqa:F401 +from pandas.core.window.exponentialmoving 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/exponentialmovingwindow.py b/pandas/core/window/exponentialmoving.py similarity index 100% rename from pandas/core/window/exponentialmovingwindow.py rename to pandas/core/window/exponentialmoving.py From 3a4be07a1cd084fee17873c790853f6a13b3fb75 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sat, 20 Jun 2020 20:06:30 +0100 Subject: [PATCH 7/9] renamed exponentialmoving back to ewm.py --- pandas/core/window/__init__.py | 2 +- pandas/core/window/{exponentialmoving.py => ewm.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename pandas/core/window/{exponentialmoving.py => ewm.py} (100%) diff --git a/pandas/core/window/__init__.py b/pandas/core/window/__init__.py index 68773b3fcc651..d6d70dcc92d60 100644 --- a/pandas/core/window/__init__.py +++ b/pandas/core/window/__init__.py @@ -1,3 +1,3 @@ -from pandas.core.window.exponentialmoving import ExponentialMovingWindow # noqa:F401 from pandas.core.window.expanding import Expanding, ExpandingGroupby # noqa:F401 +from pandas.core.window.ewm import ExponentialMovingWindow # noqa:F401 from pandas.core.window.rolling import Rolling, RollingGroupby, Window # noqa:F401 diff --git a/pandas/core/window/exponentialmoving.py b/pandas/core/window/ewm.py similarity index 100% rename from pandas/core/window/exponentialmoving.py rename to pandas/core/window/ewm.py From c37c94b110686ee24618892254c99bc12c06624a Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sat, 20 Jun 2020 20:29:40 +0100 Subject: [PATCH 8/9] pep 8 issues --- pandas/core/window/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/window/__init__.py b/pandas/core/window/__init__.py index d6d70dcc92d60..304c61ac0e489 100644 --- a/pandas/core/window/__init__.py +++ b/pandas/core/window/__init__.py @@ -1,3 +1,3 @@ -from pandas.core.window.expanding import Expanding, ExpandingGroupby # 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 From c970ce233666b8a01f8b75a4c06788e7e3713427 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sat, 20 Jun 2020 21:05:49 +0100 Subject: [PATCH 9/9] pep 8 issues --- doc/redirects.csv | 10 +++++----- doc/source/reference/window.rst | 12 ++++++------ doc/source/user_guide/computation.rst | 20 ++++++++++---------- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/frame.py | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) 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.