Skip to content

Commit

Permalink
Merge pull request #5640 from bashtage/arma-1d-check
Browse files Browse the repository at this point in the history
ENH: Improve error when ARMA endog is not 1d
  • Loading branch information
bashtage committed May 7, 2019
2 parents fb30c34 + e6e6199 commit 41a3b8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions statsmodels/tsa/arima_model.py
Expand Up @@ -430,6 +430,10 @@ 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
_endog = endog if hasattr(endog, 'ndim') else np.asarray(endog)
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 41a3b8f

Please sign in to comment.