astropy/astropy — pull request #3045 by mhvk (2014-10-21 18:59:23+00:00)
Title: Ensure Quantity.squeeze() returns a Quantity

In #3038, it was noted that `np.squeeze` does not return a `Quantity`. This seemed surprising since in the quantity source file I had noted [1] that all shape manipulation worked fine -- but clearly had omitted to actually test this properly. It turns out that internally, `ndarray.squeeze` calls `__array_wrap__` for subclasses, with `context=None` (unlike ufuncs, which set the context). So, this PR changes `Quantity..__array_wrap__` so that if context is None, it returns `self._new_view(obj)`, i.e., a Quantity view with the unit set to that of `self`.

It is possible that this has side-benefits... (or introduces problems, though all tests pass locally).

It also suggests that part of the functionaility of `_new_view` could be taken up by `__array_wrap__` -- this may need some thought, but should not really matter for this PR.

[1] https://github.com/astropy/astropy/blob/master/astropy/units/quantity.py#L1104