astropy/astropy — pull request #2270 by mhvk (2014-04-04 02:31:52+00:00)
Title: Quantity subok, and changes to __quantity_view__, __quantity_instance__

In #2259, it was suggested that `Quantity` should have a `subok` parameter, which tells whether or not to pass through subclasses. This PR implements this, and also adds the other parameters that `np.array` has (`order` and `ndmin`). As so often, the change was more disruptive than anticipated: in particular, `__quantity_instance__` and `__quantity_view__` turned out to have to become sensitive to `subok` as well, and it seemed by far the most logical way to do that was to somewhat turn around their normal behaviour: by default, they will now try to view/instantiate a `self.__class__` object (rather than the class it is defined in). This way, if one subclasses `Quantity` and does not override `__quantity_view__`, functions such as `to` will correctly return one's subclass. Without this, the simple test cases in `test_quantity.py` would fail.

@mdboom: since you wrote the original `__quantity_instance__` and `__quantity_view__`, could you have a particularly careful look? I'm still not really satisfied with these functions, feeling we should be able to do better, but do not quite know how (so best left for another PR, really).