[AstroPy] Problem with astropy 03 and quantities

Neil Crighton neilcrighton at gmail.com
Mon Nov 25 05:42:42 EST 2013


Hi Yannick,

We're also aware of the inconvenience and annoyance that
backwards-incompatible changes can cause. We try to avoid them if at all
possible. As we get closer to version 1.0 we expect that fewer such changes
will be necessary. I would hope that no further backwards-incompatible
changes are needed for cosmology after 0.3, but we can't make any promises
until version 1.0.

Neil
On 25/11/2013 9:15 PM, "Yannick Roehlly" <yannick.roehlly at lam.fr> wrote:

> Hi Thomas,
>
> Thanks for the answer.
>
> Le Mon, 25 Nov 2013 10:47:37 +0100,
> Thomas Robitaille <thomas.robitaille at gmail.com> a écrit :
>
> > First, regarding the ``copy`` issue, could you provide some code to
> > replicate this? ``copy`` should work with Quantites:
> >
> >     In [5]: np.copy(np.array([1,2,3]) * u.m)
> >     Out[5]: array([1, 2, 3])
>
> np.copy should accept an array-like but here it fails if it's an array
> of quantities.
>
>  In [16]: np.copy([x * u.m for x in xrange(10)])
>  ERROR:astropy:ValueError: setting an array element with a sequence.
>  ERROR: ValueError: setting an array element with a sequence.
>  [numpy.lib.function_base]
>
>  ---------------------------------------------------------------------------
>  ValueError                                Traceback (most recent call
>  last) <ipython-input-16-dd73be22bb28> in <module>() ----> 1 np.copy([x
>  * u.m for x in xrange(10)])
>
>  /usr/lib/pymodules/python2.7/numpy/lib/function_base.pyc in copy(a,
>  order) 828
>      829     """
>  --> 830     return array(a, order=order, copy=True)
>      831
>      832 # Basic operations
>
>  ValueError: setting an array element with a sequence.
>
> I understand that this is not a bug as everything works as expected and
> as numpy can't manage a Quantity datatype.
>
> > To adapt your code, you simply need to add ``.value`` to the quantity
> > to get the underlying Numpy array if you want to drop the units.
>
> Yes, but that means the code will not work with prior version of
> astropy. I'd better change it to have a numpy.array instead of a list
> at the point the copy fails.
>
> > There is a performance penalty in using Quantity in 0.3, but already
> > in 0.3.1 there will be significant optimizations, and given that
> > ``Quantity`` is widely used in Astropy, you can expect more work on
> > optimizations in future.
>
> My question was not for the astropy internals but for the computation
> on arrays. Thanks to the pointer Kyle gave me, I've seen that some
> optimizations made by Alex consist in splitting the value from the
> quantity, making the computations and joining them back.
>
> > By the way, there *is* an entry in the changelog:
>
> I've read it ;-) but I meant a warning, as it can break some code. But
> I admit I'm in a specific case.
>
> Cheers,
>
> Yannick
>
> --
> One can't proceed from the informal to the formal by formal means.
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20131125/8c091cda/attachment.html>


More information about the AstroPy mailing list