Astropy: Write single column to file (or create a single column Table)

Created on 23 Sep 2020  路  3Comments  路  Source: astropy/astropy

Description


I'm trying to generate a file out of a single Column object.

Expected behavior


A file with a single columns should be generated.

Actual behavior



The elements in the column are converted to columns.

Steps to Reproduce



import numpy as np
from astropy.io import ascii
from astropy.table import Table, Column
aa = np.random.uniform(0., 1., 100)
cc = Column(aa, name='data')
# Does not work
ascii.write(cc, 'data.dat')
# Converting to table has the same issue
tt = Table(cc)

System Details


Linux-5.5.0-050500-generic-x86_64-with-glibc2.10
Python 3.8.5 (default, Sep 4 2020, 07:30:14)
[GCC 7.3.0]
Numpy 1.19.1
astropy 4.0.1.post1
Scipy 1.5.2
Matplotlib 3.3.1

io.ascii question table

All 3 comments

tt = Table([cc]) works for me.

It does indeed. It also works with ascii.write([cc], 'data.dat'). I think this behaviour is a bit non-intuitive, but there's no bug here so closing. Thank you!

There is an example at https://docs.astropy.org/en/latest/table/construct_table.html#list-of-columns but perhaps it is not obvious that a list is still necessary even if you only have one column. I am glad that works for you! 馃槃

Was this page helpful?
0 / 5 - 0 ratings