Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue that caused the astropy table reader on Windows to behave differently to other platforms #2519

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion glue/core/data_factories/astropy_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def is_readable_by_astropy(filename, **kwargs):

def astropy_table_read(*args, **kwargs):

# We need to specify the encoding because otherwise on Windows the default
# encoding might be cp1252 which seems to be able to read in most binary
# files, which is an issue since it will start recognizing e.g. PNGs as
# valid tables.
encoding = 'utf-8'

from astropy.table import Table

# In Python 3, as of Astropy 0.4, if the format is not specified, the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's been closed as of 2019 I think, but having to try ASCII first now certainly holds again ;-)

Expand All @@ -40,7 +46,7 @@ def astropy_table_read(*args, **kwargs):
# also more generally, we should first try the ASCII readers.
if 'format' not in kwargs:
try:
t = Table.read(*args, format='ascii', **kwargs)
t = Table.read(*args, format='ascii', encoding=encoding, **kwargs)
# Double-check for certain FITS files that may be read in as ASCII in Python 3.11
if not (len(t) == 1 and [c.value[0] for c in t.itercols()][:3] == ['SIMPLE', '=', 'T']):
return t
Expand Down