Repository navigation
Closed
Description
Statespace models cannot be pickled on Python 3.6 . It is llikely that on previous versions of Python that are also not pickled by that this wasn't enforced. In particular, restoring them with load would likely not work perfectly.
The problem seems to be that the class uses memoryviewslice objects.
(py36) ➜ statsmodels git:(master) ✗ nosetests statsmodels/tsa/statespace/tests/test_save.py
EEEE
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_save.test_sarimax
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kevin/git/statsmodels/statsmodels/iolib/smpickle.py", line 15, in save_pickle
cPickle.dump(obj, fout, protocol=-1)
TypeError: can't pickle statsmodels.tsa.statespace._representation._memoryviewslice objects
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_save.test_structural
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kevin/git/statsmodels/statsmodels/iolib/smpickle.py", line 15, in save_pickle
cPickle.dump(obj, fout, protocol=-1)
TypeError: can't pickle statsmodels.tsa.statespace._representation._memoryviewslice objects
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_save.test_dynamic_factor
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kevin/git/statsmodels/statsmodels/iolib/smpickle.py", line 15, in save_pickle
cPickle.dump(obj, fout, protocol=-1)
TypeError: can't pickle statsmodels.tsa.statespace._representation._memoryviewslice objects
======================================================================
ERROR: statsmodels.tsa.statespace.tests.test_save.test_varmax
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kevin/git/statsmodels/statsmodels/iolib/smpickle.py", line 15, in save_pickle
cPickle.dump(obj, fout, protocol=-1)
TypeError: can't pickle statsmodels.tsa.statespace._representation._memoryviewslice objects
----------------------------------------------------------------------
Ran 4 tests in 0.131s
Activity
bashtage commentedon Jan 31, 2017
@ChadFulton Might require some custom pickling logic a la:
http://stackoverflow.com/questions/20648167/why-cant-cython-memory-views-be-pickled
ChadFulton commentedon Jan 31, 2017
Thanks for looking into this. I had meant to set up the
_data_attr_modeletc. so that all of the Cython objects were destroyed byremove_data, but I guess I missed something.In the longer run, I planned to setup a better save / load functionality in state space models, and it looks like you've already started some of that work in the PR. Thanks! Even if it's not perfect with the PR, it's better than it is now.
josef-pkt commentedon Oct 4, 2017
AFAIK this was fixed by #3402
dirolk commentedon Aug 30, 2019
use statsmodels version 0.9.0