Skip to content

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented May 28, 2014

With current master, output from a ufunc to a quantity works for two argument functions, but not for one-argument ones (see below). This PR fixes this, even though it will rarely be used.

In [1]: import astropy.units as u, numpy as np

In [2]: s = 1.*u.m

In [3]: np.arctan2(1., 1., out=s)
Out[3]: <Quantity 0.7853981633974483 rad>

In [4]: s
Out[4]: <Quantity 0.7853981633974483 rad>

In [5]: np.arctan(1., out=s)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-5673edf1ef20> in <module>()
----> 1 np.arctan(1., out=s)

/usr/lib/python2.7/dist-packages/astropy/units/quantity.pyc in __array_prepare__(self, obj, context)
    200         # the unit the output from the ufunc will have.
    201         if function in UFUNC_HELPERS:
--> 202             scales, result_unit = UFUNC_HELPERS[function](function, *units)
    203         else:
    204             raise TypeError("Unknown ufunc {0}.  Please raise issue on "

/usr/lib/python2.7/dist-packages/astropy/units/quantity_helper.pyc in helper_dimensionless_to_radian(f, unit)
     94     from .si import radian
     95     try:
---> 96         scale = unit.to(dimensionless_unscaled)
     97     except UnitsError:                                                  
     98         raise TypeError("Can only apply '{0}' function to "             

AttributeError: 'NoneType' object has no attribute 'to'

@mhvk
Copy link
Contributor Author

mhvk commented May 28, 2014

p.s. Second commit is for non-trig functions. Hopefully also gets rid of what seems random travis fail.

@mdboom
Copy link
Contributor

mdboom commented May 28, 2014

👍 (Travis failure seems unrelated).

@mhvk
Copy link
Contributor Author

mhvk commented May 30, 2014

travis failure seems unrelated again, though it complains about a missing config file, perhaps just needs #2565?

@mhvk mhvk mentioned this pull request May 30, 2014
@mhvk
Copy link
Contributor Author

mhvk commented Jun 7, 2014

@mdboom - would you like to take a last look? I think this is OK to go in.

@astrofrog astrofrog added this to the v0.4.0 milestone Jun 13, 2014
@astrofrog
Copy link
Member

This seems fine to me. @mdboom - can you confirm that it looks good to you, and we can merge this in for 0.4?

@mdboom
Copy link
Contributor

mdboom commented Jun 13, 2014

Looks fine to me. Merging.

mdboom added a commit that referenced this pull request Jun 13, 2014
…input

With quantity output, ensure non-quantity input is treated as dimensionless
@mdboom mdboom merged commit 52c46f2 into astropy:master Jun 13, 2014
@mhvk mhvk deleted the quantity-output-from-non-quantity-input branch September 26, 2014 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants