`vstack` does not preserve dtype of `Quantity` columns
See original GitHub issueDescription
When applying vstack
on two or more QTable
objects which have an integer Quantity
column, I find that the dtype
of that column is unexpectedly converted from int to float.
Minimum example:
>>> from astropy.table import QTable, vstack
>>> from astropy.units import Quantity
>>> tbl = QTable({'x': Quantity([1], dtype=int)})
>>> vstack((tbl, tbl))['x'].dtype
dtype('float64')
I expected to see dtype('int64')
above.
The error does not occur when Table
is used instead of QTable
, or when Column
is used instead of Quantity
.
Debugging attempt
My debugger shows that the following line in _vstack()
returns a Quantity with the incorrect dtype:
…unfortunately I wasn’t able to understand the DataInfo
mechanism sufficiently to understand the origin of this error.
System Details
I am using today’s master branch, i.e.
Python 3.8.6 (default, Oct 8 2020, 14:06:32)
[Clang 12.0.0 (clang-1200.0.32.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import astropy
>>> print(astropy.__version__)
4.3.dev20+g10d27d829
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
numpy: is it possible to preserve the dtype of columns when ...
When I use column_stack to concatenate NumPy arrays, the dtype gets converted:
Read more >numpy.vstack — NumPy v1.24 Manual
If provided, the destination array will have this dtype. Cannot be provided together with out. ... Stack arrays in sequence horizontally (column wise)....
Read more >Source code for astropy.table.operations
This merges column meta, which includes attributes unit, format, and description, as well as the actual `meta` attribute. It is assumed that the...
Read more >Unstack with mixed dtypes coerces everything to object #11847
Is there any reason pandas doesn't keep the np.float32 dtype, especially since it supports missing values so even when there are missing index/column...
Read more >Source code for astropy.table.operations
High-level table operations: - join() - setdiff() - hstack() - vstack() ... If the keys parameter is not defined, all columns in ``table1``...
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
@pllim Unfortunately it won’t! I just checked out #10950 and it does not fix the bug/behavior reported here. I believe this is a separate issue.
(I’m closing this issue because I’m now convinced that we shouldn’t be storing integers in Quantity objects in the first place. Please reopen if anyone disagrees!)