[Numpy-discussion] Clarifications in numpy.ma module

Nathaniel Smith njs at pobox.com
Tue Dec 30 18:23:36 EST 2014

On Tue, Dec 30, 2014 at 10:56 PM, Benjamin Root <ben.root at ou.edu> wrote:
> exception? Did you mean warning? If warning, I recall some discussion
> recently to figure out a way to hide that, but only for masked values (I
> would want to see the warning if I do bad calculations in the unmasked
> portions of my array).
> Now I see your point 3 much more clearly. I had never noticed that the
> divide could produce new masked elements. It is presumptuous to assume that
> NaNs are what I want masked. Division (and exponential) are the only two
> binary operations I can imagine where two valid floats could produce a NaN
> or Inf, so that is probably why the division was different from the others.
> This confusion probably came about in conflating valid-ness with NaN and Inf
> as concepts. In small parts of the codebase, it seems to operate with the
> concept that NaN === invalid, while other parts strictly works within the
> framework of masked === invalid.
> Of course, fixing any of this would be potentially a significant change in
> behavior. I am certainly not one to make any sort of determination on this.
> I am just a heavy user of masked arrays.

Unfortunately, as we discovered during the NA debate, it turns out
that there are several different ways to think about masked/missing
values, and np.ma kinda can't decide which one it wants to implement
so it implements a mix of all of them. This makes it difficult to know
whether it's working correctly or not :-).

@Maniteja: Also unfortunately (and probably not unrelatedly) the np.ma
code is mostly pretty old and receives only minimal maintenance. So if
you don't receive answers to your original questions it may just be
that there's no-one around who knows. "It works that way because
that's the way it works"... (My personal recommendation is to steer
clear of using np.ma entirely, but reasonable people can disagree.)


Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh

More information about the NumPy-Discussion mailing list