Skip to content

Conversation

@eteq
Copy link
Member

@eteq eteq commented Jan 25, 2013

In [1]: from astropy.units import Quantity as Q

In [2]: Q(1, 'm/s') / 2
Out[2]: <Quantity 2.0 s / (m)>

This is appears to be doing the inverse of what it should be. FWIW the actual inverse operation is correct:

In [3]: 2 / Q(1, 'm/s')
Out[3]: <Quantity 2.0 s / (m)>

This just seems to affect division by scalars. Division by other quantities (and curiously, even numpy scalars arrays) is correct:

In [12]: Q(1, 'm/s') / np.array(2)
Out[12]: <Quantity 0.5 m / (s)>

@embray
Copy link
Member Author

embray commented Jan 25, 2013

FWIW, it looks like the code for Quantity.__div__ that's causing this used to be in Quantity.__rdiv__ but was moved into __div__ as part of 24d45e2 for reasons that are unclear to me.

@eteq
Copy link
Member

eteq commented Jan 25, 2013

Definitely a bug. The "reason" was that __rdiv__ was fixed first, and the code was copied and pasted over, swapping the division order. Apparently I missed that one elif clause. It turns out that isn't necessary anyway, though, because the power of the unit is the same in __div__, unlike __rdiv__ where it's flipped.

I also added a regression test. Feel free to merge and backport immediately if you like it, @iguananaut

@embray
Copy link
Member Author

embray commented Jan 25, 2013

Cool thanks--this is exactly all I did to fix it.

embray added a commit that referenced this pull request Jan 25, 2013
Division of Quantity by a scalar wrong
@embray embray merged commit 3bbd36f into astropy:master Jan 25, 2013
embray added a commit that referenced this pull request Jan 25, 2013
Division of Quantity by a scalar wrong
keflavich pushed a commit to keflavich/astropy that referenced this pull request Oct 9, 2013
Division of Quantity by a scalar wrong
@eteq eteq deleted the issue-679 branch May 3, 2015 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants