Fix infinite recursion in units with ndarray subclasses.

This was partially addressed for masked arrays in #2290. However,
this does not work for all ndarray sub-classes, like the quantities
package. The fix here is to make sure ravel is actually succeeding
in changing the shape of the object. If it doesn't just return
what we've got.