Statsmodels: Pickling ARIMA fails

Created on 31 May 2017  路  5Comments  路  Source: statsmodels/statsmodels

ARIMA class includes dates in __getnewargs__ method. but model do not includes dates . my version is '0.8.0'.

```code.py
from statsmodels.compat.python import cPickle

cPickle.dumps(arima_mod)

=> AttributeError: 'ARIMA' object has no attribute 'dates'

type(arima_mod)

=> statsmodels.tsa.arima_model.ARIMA


```arima_model.py
    def __getnewargs__(self):
        return ((self.endog),
                (self.k_lags, self.k_diff, self.k_ma),
                self.exog, self.dates, self.freq, self.missing)

test code mod is actually ARMA model. at statsmodels/tsa/tests/test_arima.py.

def test_arima_pickle():
    endog = y_arma[:, 6]
    mod = ARIMA(endog, (1, 0, 1)
comp-tsa type-bug

Most helpful comment

@ksomemo Thank you for reporting

PR with fix is in #3785

as reference: previous PRs for __getnewargs__ #3217 and #3412

All 5 comments

Sorry, I'm slow in catching up with issues that are not on my current topic list.

to clarify the issue

if we use ARIMA(1, 1, 1) in test_arima_pickle, then it raises an error about missing dates

======================================================================
ERROR: statsmodels.tsa.tests.test_arima.test_arima_pickle
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\josef\Downloads\WinPython-64bit-3.4.4.5Qt5\python-3.4.4.amd64\l
ib\site-packages\nose\case.py", line 198, in runTest
    self.test(*self.arg)
  File "E:\Josef_new\eclipsews\statsmodels_py34_pr\statsmodels\tsa\tests\test_ar
ima.py", line 2276, in test_arima_pickle
    pkl_mod = cPickle.loads(cPickle.dumps(mod))
  File "E:\Josef_new\eclipsews\statsmodels_py34_pr\statsmodels\tsa\arima_model.p
y", line 994, in __getnewargs__
    self.exog, self.dates, self.freq, self.missing)
AttributeError: 'ARIMA' object has no attribute 'dates'

using the debugger, in the test example the other keywords are also not available except for exog

(Pdb) self.dates
*** AttributeError: 'ARIMA' object has no attribute 'dates'
(Pdb) self.freq
*** AttributeError: 'ARIMA' object has no attribute 'freq'
(Pdb) self.exog
(Pdb) self.missing
*** AttributeError: 'ARIMA' object has no attribute 'missing'

@ksomemo Thank you for reporting

PR with fix is in #3785

as reference: previous PRs for __getnewargs__ #3217 and #3412

Any known workaround before new version of library is released?

There is not direct workaround except for using the usual Python monkey patching or flexibility
e.g. setting the missing attributes might/should work
model.dates = None
model.freq = None
model.missing = None

(I haven't tried it.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

big-o picture big-o  路  3Comments

bashtage picture bashtage  路  3Comments

toobaz picture toobaz  路  6Comments

ChenChingChih picture ChenChingChih  路  3Comments

emilmirzayev picture emilmirzayev  路  5Comments