-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Round tripping non-float Quantities from QTable to fits converts all Quantities to floats #12494
Comments
The second step of the workaround
could be made a bit more convenient at least as |
As for the I/O part, I had assumed that it was a design choice to construct all Quantity-type columns as float types, but am wondering now if this has in fact been overlooked when discarding the dtype info in astropy/astropy/io/fits/connect.py Lines 100 to 103 in de53bdc
Edit: whatever the intended default behaviour, setting the attrs above will not make any difference (as the |
@samaloney I have pushed a fix for correctly reading back the mixins in #12505 ; if you have chance to test if this addresses your problems, feedback would be great. For a temporary workaround, as you noted that your use cases typically involve reading in large volumes of data, I strongly recommend to use |
Sorry for the delay @dhomeier I've just loaded some of my fits files using your branch seems to work as expected the dtypes are respected. |
Thanks for the confirmation! Note that the currently favoured implementation will store the |
Poking this one, as we've just discovered this behavior in LSST. At the very least, we should make the green note on this page more prominent. Any kind of "changes everything to a float" behavior can be dangerous for bit fields, ids or large explicitly countable values. This is related to a problem we've had with pandas, where it changes dtypes to float in order to fill in missing data with NaN. |
Description
Trying to serialise a QTable to and from fits the non-floats are always converted to floats rather then keeping the original dtypes
Expected behavior
The created QTable to have the same dtype as the underling fits column.
Actual behavior
The created QTable has converted the uint and int to float64
Steps to Reproduce
A simple but not elegant solution is to use the dtype info from the HDUL to cast the Quantity back to the desired dtypeThis actually doesn't work for the uint case or cases with mixed quantities an non-quantities
dtype([('uint', '<i2'), ('int', '<i2'), ('float32', '<f4')])
should bedtype([('uint', '<u2'), ('int', '<i2'), ('float32', '<f4')])
System Details
Linux-5.4.0-33-generic-x86_64-with-glibc2.29
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0]
Numpy 1.20.2
pyerfa 1.7.3
astropy 4.3.1
Scipy 1.6.3
Matplotlib 3.4.1
The text was updated successfully, but these errors were encountered: