astropy/astropy — pull request #3062 by mhvk (2014-10-27 19:37:45+00:00)
Title: Quantity round

Despite our fairly robust testing, it turns out `Quantity` still is not bug free:
```
import astropy.units as u, numpy as np
q = u.Quantity([1.253, 2.253], 'deg')
q.round()
# looks OK:
q.round(decimals=2)
# OOPS: array([ 1.25, 2.25])
a = np.zeros_like(q)
np.cumsum(q, out=a)
# OK:
a
# OK:
b = np.cumsum(q, out=a)
b is a
# OOPS: False
```

Here, the problem with `round(decimal=2)` arises because internally numpy multiplies and divides by `10**decimal`, using inplace changes. And the second arises because we take a `Quantity._new_view` of the numpy output, which we should not do if we already set up for inplace output.

The attached PR adds an override for `round` that solves the unit issue for all cases, and also replaces the `Quantity._prepare_output` method with a general wrapper for methods, `Quantity._wrap_function`. This reduces the boilerplace quite a bit (and should be a bit faster for in-place, and very little change for normal calculations).

Note: in the second commit are changes that are required by Quantity now correctly returning a Quantity upon rounding...