Skip to content

Commit da99346

Browse files
mroeschkenoatamir
authored andcommitted
BUG: EWM(online) not raising NotImplementedError for unsupported (pandas-dev#48834)
1 parent f88b3ff commit da99346

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

doc/source/whatsnew/v1.6.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ Plotting
238238

239239
Groupby/resample/rolling
240240
^^^^^^^^^^^^^^^^^^^^^^^^
241+
- Bug in :class:`.ExponentialMovingWindow` with ``online`` not raising a ``NotImplementedError`` for unsupported operations (:issue:`48834`)
241242
- Bug in :meth:`DataFrameGroupBy.sample` raises ``ValueError`` when the object is empty (:issue:`48459`)
242243
-
243244

pandas/core/window/ewm.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -967,10 +967,10 @@ def reset(self) -> None:
967967
self._mean.reset()
968968

969969
def aggregate(self, func, *args, **kwargs):
970-
return NotImplementedError
970+
raise NotImplementedError("aggregate is not implemented.")
971971

972972
def std(self, bias: bool = False, *args, **kwargs):
973-
return NotImplementedError
973+
raise NotImplementedError("std is not implemented.")
974974

975975
def corr(
976976
self,
@@ -979,7 +979,7 @@ def corr(
979979
numeric_only: bool = False,
980980
**kwargs,
981981
):
982-
return NotImplementedError
982+
raise NotImplementedError("corr is not implemented.")
983983

984984
def cov(
985985
self,
@@ -989,10 +989,10 @@ def cov(
989989
numeric_only: bool = False,
990990
**kwargs,
991991
):
992-
return NotImplementedError
992+
raise NotImplementedError("cov is not implemented.")
993993

994994
def var(self, bias: bool = False, *args, **kwargs):
995-
return NotImplementedError
995+
raise NotImplementedError("var is not implemented.")
996996

997997
def mean(self, *args, update=None, update_times=None, **kwargs):
998998
"""

pandas/tests/window/test_online.py

+10
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,13 @@ def test_update_times_mean(
103103
tm.assert_equal(result, expected.tail(3))
104104

105105
online_ewm.reset()
106+
107+
@pytest.mark.parametrize("method", ["aggregate", "std", "corr", "cov", "var"])
108+
def test_ewm_notimplementederror_raises(self, method):
109+
ser = Series(range(10))
110+
kwargs = {}
111+
if method == "aggregate":
112+
kwargs["func"] = lambda x: x
113+
114+
with pytest.raises(NotImplementedError, match=".* is not implemented."):
115+
getattr(ser.ewm(1).online(), method)(**kwargs)

0 commit comments

Comments
 (0)