Skip to content

Commit 3dd8987

Browse files
committed
add adjust parameter to the ewma variable times test. Add tests for disallowed decay-specification parameters when times is specified and adjust=False
1 parent 32ceb4a commit 3dd8987

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

pandas/tests/window/test_ewm.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ def test_ewma_with_times_equal_spacing(halflife_with_times, times, min_periods):
102102
tm.assert_frame_equal(result, expected)
103103

104104

105-
def test_ewma_with_times_variable_spacing(tz_aware_fixture, unit):
105+
def test_ewma_with_times_variable_spacing(tz_aware_fixture, unit, adjust):
106+
#GH 54328
106107
tz = tz_aware_fixture
107108
halflife = "23 days"
108109
times = (
@@ -112,8 +113,11 @@ def test_ewma_with_times_variable_spacing(tz_aware_fixture, unit):
112113
)
113114
data = np.arange(3)
114115
df = DataFrame(data)
115-
result = df.ewm(halflife=halflife, times=times).mean()
116-
expected = DataFrame([0.0, 0.5674161888241773, 1.545239952073459])
116+
result = df.ewm(halflife=halflife, times=times, adjust=adjust).mean()
117+
if adjust:
118+
expected = DataFrame([0.0, 0.5674161888241773, 1.545239952073459])
119+
else:
120+
expected = DataFrame([0.0, 0.23762518642226227, 1.534926369128742])
117121
tm.assert_frame_equal(result, expected)
118122

119123

@@ -148,13 +152,33 @@ def test_ewm_getitem_attributes_retained(arg, adjust, ignore_na):
148152
assert result == expected
149153

150154

151-
def test_ewma_times_adjust_false_raises():
152-
# GH 40098
155+
def test_ewma_times_adjust_false_with_disallowed_com():
156+
# GH 54328
157+
with pytest.raises(
158+
NotImplementedError, match='None of com, span, or alpha can be specified if times is provided and adjust=False'
159+
):
160+
Series(range(1)).ewm(
161+
0.1, adjust=False, times=date_range("2000", freq="D", periods=1), halflife='1D'
162+
)
163+
164+
165+
def test_ewma_times_adjust_false_with_disallowed_alpha():
166+
# GH 54328
167+
with pytest.raises(
168+
NotImplementedError, match='None of com, span, or alpha can be specified if times is provided and adjust=False'
169+
):
170+
Series(range(1)).ewm(
171+
0.1, adjust=False, times=date_range("2000", freq="D", periods=1), alpha=0.5, halflife='1D'
172+
)
173+
174+
175+
def test_ewma_times_adjust_false_with_disallowed_span():
176+
# GH 54328
153177
with pytest.raises(
154-
NotImplementedError, match="times is not supported with adjust=False."
178+
NotImplementedError, match='None of com, span, or alpha can be specified if times is provided and adjust=False'
155179
):
156180
Series(range(1)).ewm(
157-
0.1, adjust=False, times=date_range("2000", freq="D", periods=1)
181+
0.1, adjust=False, times=date_range("2000", freq="D", periods=1), span=10, halflife='1D'
158182
)
159183

160184

0 commit comments

Comments
 (0)