QTable dtype not preserved on quantity columns
See original GitHub issueIf I attribute a column with a unit, than the datatype of the column is lost. I’ve tried on Astropy 3.0.8, 2.0.3, and 1.2.1. On astropy 1.2.1 (you probably don’t care), I cannot pull the astype trick to fix the dtype afterwards, with the error “Value not scalar compatible or convertible to an int, float or complex array”
import astropy
import astropy.table
import numpy
import sys
print('Python version: '+sys.version)
print('Astropy version: '+astropy.version.version)
print('Numpy version: '+numpy.version.version)
a = astropy.table.QTable()
b = astropy.table.QTable.Column(data=numpy.zeros(1,dtype=numpy.uint8),name='Crazy',dtype=numpy.uint8,unit='m')
a.add_column(b)
# I would expect the dtype to be uint8
# If I do not set the unit above, it will be
print(repr(a))
a['Crazy'] = a['Crazy'].astype(numpy.uint8)
print(repr(a))
I’ve tried it on two setups
Python version: 2.7.15+ (default, Oct 2 2018, 22:12:08)
[GCC 8.2.0]
Astropy version: 2.0.8
Numpy version: 1.15.0
<QTable length=1>
Crazy
m
float64
-------
0.0
<QTable length=1>
Crazy
m
uint8
-----
0
Python version: 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0]
Astropy version: 3.0.3
Numpy version: 1.15.0
<QTable length=1>
Crazy
m
float64
-------
0.0
<QTable length=1>
Crazy
m
uint8
-----
0
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
QTable ignores dtype, tries converting string column with unit ...
Description I have a table that (ab)uses the "unit" metadata for some additional info on non-numeric strings, mostly by putting the String ...
Read more >Data Tables (astropy.table) — Astropy v5.2
Column d is a Quantity array. Since we used QTable , this stores a native Quantity within the table and brings the full...
Read more >Mixin columns — Astropy v1.0.4
These mixin column objects are not converted in any way but are used natively. ... QTable is exactly the same as Table except...
Read more >Saving updated dataframe from edited PyQt5 QTableView object
Columns that are specified as "Default" are kept with the original column name. Example of the Code below: form_class = uic.loadUiType(" ...
Read more >Data Tables (astropy.table) — Astropy v1.2.dev14793
Instead the table is stored as a collection of individual column objects. ... see Quantity and QTable for a way to natively use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Indeed, by default
Quantity
casts all input to float (since this makes most sense for anything with units), and thus happens when you add aColumn
item to your table. If you want to override this, you can do:Or, equivalently,
I’m going to close this issue as per my previous message, but if you feel that this issue should stay open, then feel free to re-open and remove the Close? label.
If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here