[SciPy-dev] pickle of dok_matrix fails with protocol 2

Robin robince@gmail....
Sat May 3 09:14:19 CDT 2008


Hi,

I found that trying to load a protocol 2 binary pickle of a dok_matrix
results in an error:

Protocol 1 binary and protocol 0 seem to work OK.

In [37]: Ad = sparse.dok_matrix((10,10),dtype=int8)

In [38]: Ad[2,array([1,2,3,4])]=1

In [39]: fd = open('test.pkl','wb')

In [40]: cPickle.dump(Ad,fd,2)

In [41]: fd.close()

In [42]: fd = open('test.pkl','rb')

In [43]: cPickle.load(fd)
---------------------------------------------------------------------------
<type 'exceptions.AttributeError'>        Traceback (most recent call last)

/Users/robince/phd/maxent/python/<ipython console> in <module>()

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/scipy/sparse/dok.py
in __setitem__(self, key, value)
    192                 j += self.shape[1]
    193
--> 194             if i < 0 or i >= self.shape[0] or j < 0 or j >=
self.shape[1]:
    195                 raise IndexError, "index out of bounds"
    196             if isintlike(value) and value == 0:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/scipy/sparse/base.py
in __getattr__(self, attr)
    314             return self.getnnz()
    315         else:
--> 316             raise AttributeError, attr + " not found"
    317
    318     def transpose(self):

<type 'exceptions.AttributeError'>: shape not found

In [44]: numpy.__version__
Out[44]: '1.0.5.dev4987'

In [45]: scipy.__version__
Out[45]: '0.7.0.dev4114'

In [46]: cPickle.__version__
Out[46]: '1.71'

I have submitted this as ticket #661
http://scipy.org/scipy/scipy/ticket/661

I hope this was the correct thing to do.

Robin


More information about the Scipy-dev mailing list