Repository navigation
Unit compose and equivalencies - #2559
Conversation
|
I think this is because |
|
Yes -- equivalencies in compose are broken. I spent some time looking at this last week, and I think it does make sense to fix this independently of #2544, which doesn't actually introduce any regressions in this regard. |
|
It would seem there is a general problem for equivalencies as applied to units, in that it is not possible to give just a decomposition for equivalencies that involve a scaling (like |
|
I've attached a fix that works for the examples provided. @mhvk: I'm not sure I understand your comment that this doesn't work with parameterized equivalencies. The units returned by compose always contain a scale, and will have an appropriate scale for the given equivalency. The |
|
@mdboom - thinking again, my comment may indeed be incorrect. But I'm not sure and perhaps this is easiest addressed by adding a test of what I would, perhaps naively, believe the answer should be: A propos tests, I also think it would be good to test explicitly that (maybe this needs an |
|
For the first example, that makes sense, and the result matches not which is self-consistent. If that's not correct, than the equivalency is different that what you were expecting even in the As for the second, |
|
I think the above points to my problem with But the way the equivalency is written, I see that this is essentially impossible. Note that this is similar to the temperature units, where there is a well-defined scaling between Fahrenheit, Celcius, and Kelvin, which is all one may care about for the units, but also an offset, which is important for actual quantities. In any case, I'm not sure whether we can handle this here. In practice, I think it is far more important to address #2496, which is much more likely to cause hard-to-debug problems. |
|
p.s. On |
ac0e9da to
5d6ba6b
Compare
5d6ba6b to
968db1d
Compare
|
I'd still like to see this in -- I agree with @mhvk it's not perfect, but I think it's an improvement over what we have. Perhaps a little too large/risky for a bugfix release, so we milestone this for 1.0 instead of 0.4.x? |
|
Up to you. |
Unit compose and equivalencies Conflicts: astropy/units/tests/test_equivalencies.py
In #2544, it was noted that the following does not work in master (nor is resolved by that PR):
(even though
(1*u.Unit("rad/s")).to(u.day**-1, equivalencies=u.dimensionless_angles())works fine)Looking at this further, there seems to be a general problem with using equivalencies in
compose; e.g., to me at least, in the following, the first and last are surprising:One question this brings up is whether for
composewe need equivalencies at all? They would seem to make sense only for quantities, not units (in particular for ones that include an offset, like the variousdoppler_*).