[Numpy-discussion] Warning: converting a masked element to nan

Eric Firing efiring@hawaii....
Wed Apr 23 03:00:13 CDT 2008

Vincent Schut wrote:
> Hi,
> Using maskedarrays (from svn numpy trunk), I sometimes get this warning:
> "Warning: converting a masked element to nan".
> It is not entirely clear to me what it means, and why it happens. Does 
> it mean that numpy.ma is converting an element of the data part of the 
> MA to NaN, on it's own? If so, why, and when? Or does it mean that I 
> deliberatly have changed a data element to NaN, and if so, why on earth 
> should I be warned for that? I think it is pretty normal to be able to 
> create NaN's in my array... Or does it mean yet something else?
> And, also important: how can I avoid this (not suppress, but what should 
> I stop doing that currently triggers this warning)?
> I hope someone could eleborate a bit on this...

Maybe you are doing something equivalent to this:

In [1]:xx = ma.array([1.1,2.2], mask=[True,False])

In [2]:float(xx)
UserWarning: Warning: converting a masked element to nan.
   warnings.warn("Warning: converting a masked element to nan.")

It is the __float__ method of the masked array that gives this warning.

I think there is a bug in that method; it always returns a nan, 
sometimes with the warning, and sometimes without.  By analogy with the 
ndarray method, it should raise an exception if the array has more than 
one element, and it there is only one element, it should try to convert 
it to a python float.


> Cheers,
> Vincent.
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

More information about the Numpy-discussion mailing list