astropy/astropy — pull request #1558 by mhvk (2013-10-10 18:27:35+00:00)
Title: Units-quantity interaction simplification

At present, when I do, e.g., `10. * u.m`, this leads `Unit.__mul__` to return `Quantity(10., u.m)`. This is fine for this specific case, but becomes problematic if the value is, e.g., a `MaskedArray`, as then the mask is silently dropped. This PR implements a different logic: if the item being multiplied with is not consistent with being a Unit, the unit converts itself to a Quantity with value of 1, and retries the multiplication, i.e., do `10. * Quantity(1, u.m)` in the example above. Thus, one avoids presuming the result of something that should really be left to `Quantity.__mul__`. Happily, it leads to a net decrease in the number of lines of code. (But also triggers one test failure, which I marked `xfail` as it is not directly a consequence of this PR; see #1557)

p.s. Slightly running ahead of the upcoming PR for `MaskedQuantity`, I do not want to have `Quantity(masked_array, unit)` return a `MaskedQuantity`, since that is contrary to the behaviour of both `np.array` and `Column`, both of which simply strip the mask.