Skip to content

Statespace models are not pickleable on Python 3.6 #3401

Closed

Description

@bashtage

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

  1. ChadFulton commented on Jan 31, 2017

    @ChadFulton
    Member

    Thanks for looking into this. I had meant to set up the _data_attr_model etc. so that all of the Cython objects were destroyed by remove_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.

  2. josef-pkt commented on Oct 4, 2017

    @josef-pkt
    Member

    AFAIK this was fixed by #3402

  3. added this to the 0.9 milestone on Oct 4, 2017
  4. dirolk commented on Aug 30, 2019

    @dirolk

    use statsmodels version 0.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions