[Numpy-discussion] Bug in pickling an ndarray?

Daniel Hyams dhyams@gmail....
Sat Jun 30 19:04:46 CDT 2012

Thanks Travis and Robert for the clarification; it is much more clear
what is going on now.

As the demo code shows, also a.flags['OWNDATA'] is different on its
way out of the pickle; which also makes sense now.  So using that flag
instead of checking a.base for None is equivalent, at least in this

So is it a bug, then, that, on Windows, .base is set to None (of
course, this may be something that was fixed in later versions of
numpy; I was only able to test Windows with numpy 1.4.1).

I'll just make a copy and discard the original to work around the
situation (which is what I already had done, but the inconsistent
behavior across versions and platforms made me think it was a bug).

Thanks again for the clear explanation of what is going on.

On Sat, Jun 30, 2012 at 6:33 PM, Daniel Hyams <dhyams@gmail.com> 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@gmail.com

Daniel Hyams
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120630/bbd9b46f/attachment.html 

More information about the NumPy-Discussion mailing list