Skip to content

Commit

Permalink
ENH: Improve error when ARMA endog is not 1d
Browse files Browse the repository at this point in the history
Improve explanation when passing an array that is not 1d or 1 column, 2d

closes #2575
  • Loading branch information
bashtage committed May 7, 2019
1 parent 6453c81 commit c9b96d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions statsmodels/tsa/arima_model.py
Expand Up @@ -430,6 +430,9 @@ class ARMA(tsbase.TimeSeriesModel):
def __init__(self, endog, order, exog=None, dates=None, freq=None,
missing='none'):
super(ARMA, self).__init__(endog, exog, dates, freq, missing=missing)
# GH 2575
if (endog.ndim == 2 and endog.shape[1] != 1) or endog.ndim > 2:
raise ValueError('endog must be 1-d or 2-d with 1 column')
exog = self.data.exog # get it after it's gone through processing
_check_estimable(len(self.endog), sum(order))
self.k_ar = k_ar = order[0]
Expand Down
14 changes: 14 additions & 0 deletions statsmodels/tsa/tests/test_arima.py
Expand Up @@ -2432,3 +2432,17 @@ def test_endog_int():
resf = ARIMA(yf.cumsum(), order=(1, 1, 1)).fit(disp=0)
assert_allclose(res.params, resf.params, rtol=1e-6, atol=1e-5)
assert_allclose(res.bse, resf.bse, rtol=1e-6, atol=1e-5)


def test_multidim_endog(reset_randomstate):
y = np.random.randn(1000, 2)
with pytest.raises(ValueError):
ARMA(y, order=(1, 1))

y = np.random.randn(1000, 1, 2)
with pytest.raises(ValueError):
ARMA(y, order=(1, 1))

y = np.random.randn(1000, 1, 1)
with pytest.raises(ValueError):
ARMA(y, order=(1, 1))

0 comments on commit c9b96d7

Please sign in to comment.