New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Squared Column/Quantity does not square unit (v3.1.2) #8918
Comments
Funnily enough, doing energies.to(energies.unit) right before doing all the operations makes it behave as I would expect. |
@mireianievas , thanks for reporting this. Just so we are all on the same page, can you please provide a minimal example of how the input table was constructed? Also, please provide Numpy version. |
#!/bin/env python3
import astropy
from astropy.table.column import Column
import astropy.units as units
energies = Column(data=[1,2,3,4],name="E",unit="TeV")
# returns the column with TeV as unit:
print(energies)
# returns the column with contents^2 but units unchanged:
print(energies**2)
# returns the column with contents^2 but units unchanged:
print(energies*energies)
# .to() converts the column into a Quantity, then the units are transformed as expected:
print(energies.to("TeV")**2) |
@taldcroft or @mhvk , can you please comment on the reported @mireianievas , FWIW if you pass the column into a >>> from astropy.table import QTable
>>> t = QTable([energies])
>>> t['E'] ** 2
<Quantity [ 1., 4., 9., 16.] TeV2> |
@mireianievas - |
p.s. Looking at the documentation, it took me a bit more time than I had hoped to find the above link. |
Definitely agree. I would suggest to remove the early example that begins with "A column with a unit works with and can be easily converted to an Quantity object (but see Quantity and QTable for a way to natively use Quantity objects in tables):". Replace that with an example that says, if you are working with data that have units, use QTable and Quantity. End of story. Then deep in the docs mention that Column has some quantity-like behavior that provides limited compatibility but is generally not recommended. |
And 👍 to generally scrubbing the table docs to give more emphasis to QTable. E.g. it might be fine and appropriate to put the QTable example as the 2nd example in the Table Getting Started. |
Sounds good! @mireianievas - in many ways, changes to the documentation are best done by people who just learned how things work, rather than by developers who often implicitly assume things. Any chance you might be able to help make the changes? (Definitely do not feel obligated; just having your issue here clearly already helped, as it made us realize the documentation could be better.) |
Hi, thanks for all the info. I looked into the wiki and to be honest, it is pretty clear as it is now, now it makes total sense. I just had the doubt because I was not expecting that behavior and it is not straightforward to come with the right keywords to look for it. But probably I should have spent a bit more time looking for this. |
@mireianievas , no worries. If you had problem finding the info, you won't be the only one. The documentation could be improved. Thanks for looking into this, @taldcroft and @mhvk ! |
Hey...I would like to address this issue. Is it okay @mhvk? |
Closing this since #9143 addressed this mostly. |
I am pretty surprised to see this behavior with some astropy quantities in 3.1.2 while working with some gamma-ray data.
Is this expected?
The text was updated successfully, but these errors were encountered: