question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`vstack` does not preserve dtype of `Quantity` columns

See original GitHub issue

Description

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:

https://github.com/astropy/astropy/blob/10d27d8292bafb3ab502f4147dd707473e69af71/astropy/table/operations.py#L1288

…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:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
barentsencommented, Oct 28, 2020

@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.

0reactions
barentsencommented, Oct 29, 2020

(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!)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found