io.ascii basic and fixed_width formats do not round-trip boolean data
See original GitHub issueDescription
When reading back an astropy table that had been written in fixed_width_two_line format and had contained a boolian column, the boolean values get read back as a string
Expected behavior
I expected to get the table back in the formats in which it was writen
Actual behavior
As noted, I got back a string value for True or False, and so I could not run the same code on the table that I could run before it was written out.
Steps to Reproduce
- [First Step]
- [Second Step]
- [and so on…]
from astropy.table import Table
import numpy as np
z=np.linspace(0,50)
x=Table([z,z],names=['foo','goo'])
x['Good']=True
x.info()
x.write('foo.txt',format='ascii.fixed_width_two_line',overwrite=True)
xx=ascii.read('foo.txt')
xx.info()
Here is what this produces
from astropy.table import Table
import numpy as np
z=np.linspace(0,50)
x=Table([z,z],names=['foo','goo'])
x['Good']=True
x.info()
x.write('foo.txt',format='ascii.fixed_width_two_line',overwrite=True)
xx=ascii.read('foo.txt')
xx.info()
<Table length=50>
name dtype
---- -------
foo float64
goo float64
Good bool
<Table length=50>
name dtype
---- -------
foo float64
goo float64
Good str4
System Details
import platform; print(platform.platform()) Darwin-19.6.0-x86_64-i386-64bit import sys; print(“Python”, sys.version) Python 3.7.11 (default, Jul 27 2021, 07:03:16) [Clang 10.0.0 ] import erfa; print(“pyerfa”, erfa.version) pyerfa 1.7.1.1 import astropy; print(“astropy”, astropy.version) astropy 4.2 import scipy; print(“Scipy”, scipy.version) Scipy 1.4.1 import matplotlib; print(“Matplotlib”, matplotlib.version) Matplotlib 3.5.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (16 by maintainers)
Top GitHub Comments
These days I’m less and less inclined to have configuration options that silently change the behavior of code. In other words when a line of code or function behaves fundamentally differently based on a config item, then that makes it hard for readers of the code to know what it will do.
Instead, even if it is a little less convenient, it is better to be explicit.
Oh, wait… maybe I typed it wrong. Seems to work now!