[Numpy-discussion] Bug in pickling an ndarray?

Travis Oliphant travis at continuum.io
Sat Jun 30 18:37:02 EDT 2012


This is the expected behavior.   It is not a bug. 

NumPy arrays after pickling are views into the String that is created by the pickling machinery.   Thus, the base is set.  This was done to avoid an additional memcpy. 

This avoids a copy, but yes, it does mean that you can't resize the array until you make another copy. 

Best regards,

-Travis



On Jun 30, 2012, at 5:33 PM, Daniel Hyams wrote:

> Hmmm, I wouldn't think that it is correct behavior; I would think that *any* ndarray arising from pickling would have its .base attribute set to None.  If not, then who is really the one that owns the data? 
> 
> It was my understanding that .base should hold a reference to another ndarray that the data is really coming from, or it's None.  It certainly shouldn't be some random string, should it?
> 
> And yes, it is causing a problem for me, which is why I noticed it.  In my application, ndarrays can come from various sources, pickling being one of them.  Later in the app, I was wanting to resize the array, which you cannot do if the data is not really owned by that array...I had explicit check for myarray.base==None, which it is not when I get the ndarray from a pickle.
> 
> 
> -- 
> Daniel Hyams
> dhyams at gmail.com
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120630/2c5bab0b/attachment.html>


More information about the NumPy-Discussion mailing list