I would say it is an ma bug, but don't know how to fix it properly without changing numpy scalar arithmetic to call an enhanced version of __array__ and pass context in. The core problem can be demonstrated by the following session:

from numpy import * x = ma.array([1],mask=[1])

int_(1)*x Traceback (most recent call last): File "<stdin>", line 1, in ? File ".../numpy/core/ma.py", line 622, in __array__ raise MAError, \ numpy.core.ma.MAError: Cannot automatically convert masked array to numeric because data is masked in one or more locations.

Note that x*int_(1) works as expected. This is so because python dispatches multiplication to int.__mul__ rather than ma.array.__mul__ if int_(1) is the first multiplicand. I've fixed a similar problem for array*ma.array case and array(1)*x works in the current version of numpy. I will not have time to work on this before the weekend, so if someone is motivated enought to fix this bug before the upcoming release, please take a look at http://projects.scipy.org/scipy/numpy/wiki/MaskedArray ("Ufuncs and Masked Arrays"). It should be straightforward to generalize that approach for array scalars. On 3/9/06, Eric Firing <efiring@hawaii.edu> wrote:

Travis et al.,

Jeff Whitaker found that the imaged_masked.py example (with the colorbar line uncommented) in matplotlib 0.87 triggered a numpy bug--the script works normally with Numeric and numarray. He committed a workaround to mpl svn, but I suspect you may want to track it down and squash it in numpy before the next release. It is not clear to me whether it is really in ma, or merely revealed by ma. The attached script triggers the bug.

Thanks.

Eric