You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tables with 2D columns of strings fail round trip to FITS format under py3 #5287
In [1]: #- Tables with 1D columns of strings can round-trip to FITS just fine, including
...: #- the encoding/decoding to get form unicode to bytes and back
...: t1=Table()
...: t1['x'] = ['aa', 'bb', 'cc']
...: t1.write('t1.fits', overwrite=True)
...: t2=Table.read('t1.fits')
...: t1.dtype, t2.dtype
...:
Out[1]: (dtype([('x', '<U2')]), dtype([('x', '<U2')]))
In [2]: t1['x'] ==t2['x']
...:
Out[2]: array([ True, True, True], dtype=bool)
In [3]: #- Add a 2D column of strings and try again:
...: t2['y'] = [['x', 'xx'], ['y', 'yy'], ['z', 'zz']]
...: t2.write('t2.fits', overwrite=True)
...: t3=Table.read('t2.fits')
...: t2.dtype, t3.dtype
...:
Out[3]:
(dtype([('x', '<U2'), ('y', '<U2', (2,))]),
dtype([('x', '<U2'), ('y', '<U8', (2,))]))
Note that the dtype for 'y' column has changed from '<U2' to '<U8'.
This works for python 2.7, where the dtype remains 'S2'.
Note that this problem is covered by the unit tests reported in #5280, but the discussion there has focused on the underlying io.fits library and how to create a BinTableHDU, so I'm separating this out as a separate Table-focused issue since that isolates the user from the underlying I/O library.
Activity