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

BUG: fix write/read roundtrips with empty Table dumped to ECSV #15885

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions astropy/io/ascii/ecsv.py
Expand Up @@ -176,8 +176,13 @@

# Read the first non-commented line of table and split to get the CSV
# header column names. This is essentially what the Basic reader does.
header_line = next(super().process_lines(raw_lines))
header_names = next(self.splitter([header_line]))
try:
header_line = next(super().process_lines(raw_lines))
header_names = next(self.splitter([header_line]))
except StopIteration:

Check warning on line 182 in astropy/io/ascii/ecsv.py

View check run for this annotation

Codecov / codecov/patch

astropy/io/ascii/ecsv.py#L182

Added line #L182 was not covered by tests
# there are no non-commented lines
header_line = ""
header_names = []

Check warning on line 185 in astropy/io/ascii/ecsv.py

View check run for this annotation

Codecov / codecov/patch

astropy/io/ascii/ecsv.py#L184-L185

Added lines #L184 - L185 were not covered by tests

# Check for consistency of the ECSV vs. CSV header column names
if header_names != self.names:
Expand Down
9 changes: 9 additions & 0 deletions astropy/io/ascii/tests/test_ecsv.py
Expand Up @@ -156,6 +156,15 @@ def test_write_read_roundtrip():
assert np.all(t[name] == t2[name])


def test_write_read_roundtrip_empty_table(tmp_path):
# see https://github.com/astropy/astropy/issues/13191
sfile = tmp_path / "x.ecsv"
Table().write(sfile)
t = Table.read(sfile)
assert len(t) == 0
assert len(t.colnames) == 0


def test_bad_delimiter():
"""
Passing a delimiter other than space or comma gives an exception
Expand Down
1 change: 1 addition & 0 deletions docs/changes/units/15885.bugfix.rst
@@ -0,0 +1 @@
Fix write/read roundtrips with empty ``Table`` dumped to ECSV.