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.

Table.read('file.fits', format='ascii') does not raise under Python 3.11

See original GitHub issue

Description

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:closed
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
taldcroftcommented, Sep 16, 2022

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.

0reactions
github-actions[bot]commented, Sep 24, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's New In Python 3.11 — Python 3.11.1 documentation
This article explains the new features in Python 3.11, compared to 3.10. ... information that is not available at the time when the...
Read more >
Python 3.11: Cool New Features for You to Try - Real Python
In this tutorial, you'll explore what Python 3.11 brings to the table. You'll learn how Python 3.11 is the fastest and most user-friendly ......
Read more >
Tecplot 360 User's Manual
It should not be interpreted as a commitment by Tecplot, Inc. Tecplot, ... Generate a Tecplot-format ASCII data file - Read it into...
Read more >
JWST Pipeline Documentation
You can execute a pipeline or a step from within python by using the ... is read from the extension when a FITS...
Read more >
GNU Astronomy Utilities
10.4 Viewing FITS file contents with DS9 or TOPCAT ... You do not need to read or even fully understand the whole thing,...
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