You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like the astropy units module a lot. Thanks for this great piece of work!
I think, I encountered a bug related to the Quantities class. When I use logarithmic units, the constructor seems to change the type of the unit. This does not happen, when I simply multiply with the unit:
q1.to(dimless) # <Quantity [ 1.25892541, 1.99526231, 3.16227766]>q2.to(dimless) # UnitConversionError: 'dB' and '' (dimensionless) are not# convertible@u.quantity_input(a=dB)defmy_func(a):
print(a)
my_func(q1) # [ 1. 3. 5.] dBmy_func(q2) # UnitsError: Argument 'a' to function 'my_func' must be in# units convertible to 'dB'.
Hmm, this is similar to #5851, where the question was why Quantity constructor did not return a function quantity such as Magnitude when passed a magnitude unit. As discussed there, in general, one wants to have a class initializer return an instance of that class. So, here, the initializer returns a Quantity with units of u.dB since that is the same thing as u.dB(u.one) - it fails it you do u.Quantity(1., u.dB(u.mW)). Following #5851, we decided that we would at least allow this to work if one passed in subok=True (this works since u.Dex is a subclass of Quantity). So, I think that answers part of your question - the main question here is whether we could perhaps document this better? (though it is in the help for Quantity in the latest version)
However, you also raise a new issue here, that quantity_input does not work in your example. I do think this would have to be a=u.dB(u.dimensionless_unscaled), but that doesn't work either. It should be possible to make this work, perhaps with subok=True used by default, or by allowing to request a specific quantity subclass. cc @adrn, @Cadair who wrote quantity_input.
Thanks a lot. Using subok=True indeed fixes most of my problems, except the one with quantity_input. Perhaps, as you say, the subok=True should be made default? I'm developing a new package and therefore, not only astropy docs need to clarify this, but I'd also need to do it in my docs, which would add a lot of overhead.
@Cadair - as you have just been looking at quantity_input, what do you think of using subok=True by default in the Quantity constructor, so that things work for logarithmic units as well? (this issue)
I like the astropy units module a lot. Thanks for this great piece of work!
I think, I encountered a bug related to the Quantities class. When I use logarithmic units, the constructor seems to change the type of the unit. This does not happen, when I simply multiply with the unit:
This is a problem for some of my use cases:
I can work-around the first problem:
But now the decorated function fails in both cases (with a different error!)
The text was updated successfully, but these errors were encountered: