Skip to content

Commit b203eac

Browse files
committed
BUG: Correct method setting in ThetaModel
Correct auto method selection which lead to multiplicative being ignored
1 parent 3e739c2 commit b203eac

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

statsmodels/tsa/forecasting/tests/test_theta.py

+10
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,13 @@ def test_forecast_seasonal_alignment(data, period):
133133
index = np.arange(data.shape[0], data.shape[0] + comp.shape[0])
134134
expected = seasonal[index % period]
135135
np.testing.assert_allclose(comp.seasonal, expected)
136+
137+
138+
def test_auto(reset_randomstate):
139+
e = np.random.standard_normal(100).cumsum()
140+
y = 10 + e - e.min()
141+
tm = ThetaModel(y, method="auto")
142+
assert tm.method == "mul"
143+
144+
tm = ThetaModel(y - 20, method="auto")
145+
assert tm.method == "add"

statsmodels/tsa/forecasting/theta.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ def _deseasonalize_data(self) -> Tuple[np.ndarray, np.ndarray]:
183183
y = self._y
184184
if not self._has_seasonality:
185185
return self._y, np.empty(0)
186-
self._method = (
187-
"mul" if self._method == "auto" and self._y.min() > 0 else "add"
188-
)
186+
if self._method == "auto":
187+
self._method = "mul" if self._y.min() > 0 else "add"
189188

190189
res = seasonal_decompose(y, model=self._method, period=self._period)
191190
if res.seasonal.min() <= 0:

0 commit comments

Comments
 (0)