Skip to content

Commit

Permalink
Simplify opening file in write_table
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Mar 18, 2022
1 parent 82cc212 commit b169b4a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
12 changes: 1 addition & 11 deletions ctapipe/io/astropy_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"""
Functions to help adapt internal ctapipe data to astropy formats and conventions
"""

from pathlib import Path
import os
from contextlib import ExitStack

Expand Down Expand Up @@ -122,16 +120,8 @@ def write_table(table, h5file, path, append=False, mode="a", filters=DEFAULT_FIL
copied = False

with ExitStack() as stack:

if isinstance(h5file, (str, Path)):
if not isinstance(h5file, tables.File):
h5file = stack.enter_context(tables.open_file(h5file, mode=mode))
elif isinstance(h5file, tables.file.File):
pass
else:
raise ValueError(
f"expected a string, Path, or PyTables "
f"filehandle for argument 'h5file', got {h5file}"
)

attrs = {}
for colname, column in table.columns.items():
Expand Down
2 changes: 1 addition & 1 deletion ctapipe/io/tests/test_write_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ def test_invalid_input():
"""Test invalid path argument raises"""
from ctapipe.io.astropy_helpers import write_table

with pytest.raises(ValueError):
with pytest.raises(TypeError):
invalid_path = 5
write_table(Table({"a": [1, 2, 3]}), invalid_path, "/temp")

0 comments on commit b169b4a

Please sign in to comment.