[Numpy-discussion] Bug in pickling an ndarray?

Daniel Hyams dhyams@gmail....
Sat Jun 30 15:15:49 CDT 2012


I am having trouble pickling (and then unpickling) an ndarray. Upon
unpickling, the "base" attribute of the ndarray is set to some very strange
string ("base" was None when the ndarray was pickled, so it should remain
None).

I have tried on various platforms and versions of numpy, with inconclusive
results:

# tested: Linux (Suse 11.1), numpy 1.5.1       BUG
#         Linux (Suse 11,0), numpy 1.6.1       OK
#         Linux (Mint Debian), numpy 1.6.1     BUG
#         Linux (Mint Debian), numpy 1.6.2     BUG
#         OSX (Snow Leopard),  numpy 1.5.1rc1  BUG
#         OSX (Snow Leopard),  numpy 1.6.2     BUG
#         Windows 7,           numpy 1.4.1     OK

I have attached a script below that can be used to check for the problem; I
suppose that this is a bug report, unless I'm doing something terribly
wrong or my expectations for the base attribute are off.

---------------- cut here ---------------------------------
# this little demo shows a problem with the base attribute of an ndarray,
when
# pickling.  Before pickling, dset.base is None, but after pickling, it is
some
# strange string.

import cPickle as pickle
import numpy
print numpy.__version__
#import pickle

dset = numpy.ones((2,2))

print "BEFORE PICKLING"
print dset
print "base = ",dset.base
print dset.flags

# pickle.
s = pickle.dumps(dset)

# now unpickle.
dset = pickle.loads(s)

print "AFTER PICKLING AND THEN IMMEDIATELY UNPICKLING"
print dset
print "base = ",dset.base
print dset.flags


-- 
Daniel Hyams
dhyams@gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120630/8b2b71d6/attachment.html 


More information about the NumPy-Discussion mailing list