numpy/numpy — pull request #3900 by mhvk (2013-10-12 16:25:43+00:00)
Title: BUG Ensure NotImplemented is passed on in MaskedArray ufunc's

Currently, masked array `ufunc` replacements do not check whether the `ufunc` call on the data proper actually works (see below). This PR ensures that they pass on `NotImplemented` if needed, so that classes more interesting than the `string` below will have a chance to try to do the reverse operation.

Note that this is a long-standing bug; I'm not sure how far it can be backported, but hope it can make 1.8.0.

p.s. The reason I stumbled upon this is that I am trying to implement a `MaskedQuantity` class for `astropy` [1]. For this package, we already have `Unit` and `Quantity` classes, and set it up such that `array * unit` returns a `Quantity`; I'd hope to do have `masked_array * unit` similarly to return a `MaskedQuantity`.

[1] http://docs.astropy.org/en/latest/units/quantity.html

```

In [6]: np.array([1.,2.]).__mul__('abc')
Out[6]: NotImplemented

In [7]: np.ma.MaskedArray([1.,2.]).__mul__('abc')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
----> 1 np.ma.MaskedArray([1.,2.]).__mul__('abc')

/usr/lib/pymodules/python2.7/numpy/ma/core.pyc in __mul__(self, other)
3646 def __mul__(self, other):
3647 "Multiply other by self, and return a new masked array."
-> 3648 return multiply(self, other)
3649 #
3650 def __rmul__(self, other):

/usr/lib/pymodules/python2.7/numpy/ma/core.pyc in __call__(self, a, b, *args, **kwargs)
938 np.seterr(**err_status_ini)
939 # Case 1. : scalar
--> 940 if not result.ndim:
941 if m:
942 return masked

AttributeError: 'NotImplementedType' object has no attribute 'ndim'
```