Table.read('file.fits', format='ascii') does not raise under Python 3.11
See original GitHub issueDescription
For certain FITS BINTABLE files, with Python 3.11.0rc2 a forced attempt to read them with format='ascii'
does not raise the expected exception but rather reads the table bytes in as table columns.
Expected behavior
io.ascii
should raise something like a _csv.Error
so a reader can handle the exception to try a different format
(arguably it is not 100% clear whether this really should constitute a bug, since we were explicitly forcing Table.read()
to treat it as ascii, but currently it is at least problematic due to the inconsistency with earlier Python versions).
Actual behavior
The FITS file is parsed as an ASCII table of dtype([('col1', '<U6'), ('col2', '<U1'), ('col3', '<U1'), ... ('col104', '<U3'), ('col105', '<U2880')])
Steps to Reproduce
Downloading e.g. https://github.com/glue-viz/glue/blob/main/glue/tests/data/single_table.fits or creating a simple example as below.
tb = Table([np.arange(1, 4), np.arange(4, 7)], names=['a', 'b'])
Table.write('single_table.fits')
Python 3.10
tab = Table.read('single_table.fits', format='ascii')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/lib/python3.10/site-packages/astropy/table/connect.py", line 62, in __call__
out = self.registry.read(cls, *args, **kwargs)
File "/opt/lib/python3.10/site-packages/astropy/io/registry/core.py", line 212, in read
data = reader(*args, **kwargs)
File "/opt/lib/python3.10/site-packages/astropy/io/ascii/connect.py", line 18, in io_read
return read(filename, **kwargs)
File "/opt/lib/python3.10/site-packages/astropy/io/ascii/ui.py", line 359, in read
dat = _guess(table, new_kwargs, format, fast_reader)
File "/opt/lib/python3.10/site-packages/astropy/io/ascii/ui.py", line 526, in _guess
dat = reader.read(table)
File "/opt/lib/python3.10/site-packages/astropy/io/ascii/core.py", line 1365, in read
self.header.get_cols(self.lines)
File "/opt/lib/python3.10/site-packages/astropy/io/ascii/core.py", line 631, in get_cols
self.names = next(self.splitter([line]))
File "/opt/lib/python3.10/site-packages/astropy/io/ascii/core.py", line 489, in __call__
for vals in csv_reader:
_csv.Error: line contains NUL
Python 3.11
Table.read('single_table.fits')
<Table length=3>
a b
int64 int64
----- -----
1 4
2 5
3 6
Table.read('single_table.fits', format='ascii')
<Table length=1>
col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 ... col96 col97 col98 col99 col100 col101 col102 col103 col104 col105
str6 str1 str1 str1 str8 str2 str4 str8 str6 str1 ... str6 str1 str2 str1 str6 str1 str2 str1 str3 str2880
------ ---- ---- ---- -------- ---- ---- -------- ------ ----- ... ------ ----- ----- ----- ------ ------ ------ ------ ------ ------------------------------------------------
SIMPLE = T / conforms to FITS standard BITPIX = ... TTYPE2 = 'b ' TFORM2 = 'K ' END
System Details
platform linux – Python 3.11.0rc2 astropy @ git+https://github.com/astropy/astropy@616f382dc9be9f52954841c80f4eed5485a3d1e8 numpy @ git+https://github.com/numpy/numpy@5f94eb858f3e181eccfda2c26db9f0b9167a8156
or same on macOS-12.6-arm64-arm-64bit, or with astropy 5.1 numpy 1.23.3
Issue Analytics
- State:
- Created a year ago
- Comments:11 (9 by maintainers)
Top GitHub Comments
I agree with @pllim - if you explicitly tell astropy to do something non-sensical then we should not expend effort to guard against that. There are plenty of real issues that would benefit more users if they got fixed.
I’m going to close this issue as per my previous message, but if you feel that this issue should stay open, then feel free to re-open and remove the Close? label.
If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here