From ffc6a3810c1a051ae105d6476f52d6ea65123a11 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 8 Mar 2021 21:10:05 -0800 Subject: [PATCH] ERR: Raise NotImplimentedError for EWMA with times and adjust=False --- doc/source/whatsnew/v1.3.0.rst | 1 + pandas/core/window/ewm.py | 2 ++ pandas/tests/window/test_ewm.py | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 370ea28832758..ac5ad12a992b7 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -570,6 +570,7 @@ Groupby/resample/rolling - Bug in :meth:`DataFrameGroupBy.sample` where column selection was not applied to sample result (:issue:`39928`) - Bug in :class:`core.window.ewm.ExponentialMovingWindow` when calling ``__getitem__`` would incorrectly raise a ``ValueError`` when providing ``times`` (:issue:`40164`) - Bug in :class:`core.window.ewm.ExponentialMovingWindow` when calling ``__getitem__`` would not retain ``com``, ``span``, ``alpha`` or ``halflife`` attributes (:issue:`40164`) +- :class:`core.window.ewm.ExponentialMovingWindow` now raises a ``NotImplementedError`` when specifying ``times`` with ``adjust=False`` due to an incorrect calculation (:issue:`40098`) Reshaping ^^^^^^^^^ diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 6310a751492da..4537e525c5086 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -255,6 +255,8 @@ def __init__( self.ignore_na = ignore_na self.times = times if self.times is not None: + if not self.adjust: + raise NotImplementedError("times is not supported with adjust=False.") if isinstance(self.times, str): self.times = self._selected_obj[self.times] if not is_datetime64_ns_dtype(self.times): diff --git a/pandas/tests/window/test_ewm.py b/pandas/tests/window/test_ewm.py index 3e823844c7f56..8da902ea830d1 100644 --- a/pandas/tests/window/test_ewm.py +++ b/pandas/tests/window/test_ewm.py @@ -171,3 +171,13 @@ def test_ewm_vol_deprecated(): result = ser.ewm(com=0.1).vol() expected = ser.ewm(com=0.1).std() tm.assert_series_equal(result, expected) + + +def test_ewma_times_adjust_false_raises(): + # GH 40098 + with pytest.raises( + NotImplementedError, match="times is not supported with adjust=False." + ): + Series(range(1)).ewm( + 0.1, adjust=False, times=date_range("2000", freq="D", periods=1) + )