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 1 commit
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
10 changes: 8 additions & 2 deletions 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,15 +46,15 @@ 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
except Exception:
pass

# If the above didn't work, attempt to read with no specified format
return Table.read(*args, **kwargs)
return Table.read(*args, encoding=encoding, **kwargs)
dhomeier marked this conversation as resolved.
Show resolved Hide resolved


@data_factory(label="Catalog (astropy.table parser)",
Expand Down
Loading