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

Do not use pathlib for hdf5 datasets, fixes #2318 #2319

Merged
merged 1 commit into from
May 10, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions ctapipe/io/hdf5merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..instrument.subarray import SubarrayDescription
from ..utils.arrays import recarray_drop_columns
from . import metadata
from .hdf5tableio import DEFAULT_FILTERS, get_column_attrs, get_node_meta
from .hdf5tableio import DEFAULT_FILTERS, get_column_attrs, get_node_meta, split_h5path


class NodeType(enum.Enum):
Expand Down Expand Up @@ -78,20 +78,6 @@ class CannotMerge(IOError):
"""Raised when trying to merge incompatible files"""


def split_h5path(path):
"""
Split a path inside an hdf5 file into parent / child
"""
if not path.startswith("/"):
raise ValueError("Path must start with /")

head, _, tail = path.rstrip("/").rpartition("/")
if head == "":
head = "/"

return head, tail


class HDF5Merger(Component):
"""
Class to copy / append / merge ctapipe hdf5 files
Expand Down
22 changes: 17 additions & 5 deletions ctapipe/io/hdf5tableio.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this use of paths inside of h5 files tested somewhere? I took a look at io/tests/test_hdf5.py but I nothing stands out as testing the access of paths inside of a file.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
TimeColumnTransform,
)

__all__ = ["HDF5TableWriter", "HDF5TableReader"]
__all__ = ["HDF5TableWriter", "HDF5TableReader", "split_h5path"]

PYTABLES_TYPE_MAP = {
"float": tables.Float64Col,
Expand Down Expand Up @@ -48,6 +48,20 @@
)


def split_h5path(path):
"""
Split a path inside an hdf5 file into parent / child
"""
if not path.startswith("/"):
raise ValueError("Path must start with /")

head, _, tail = path.rstrip("/").rpartition("/")
if head == "":
head = "/"

return head, tail


def get_hdf5_attr(attrs, name, default=None):
if name in attrs:
return attrs[name]
Expand Down Expand Up @@ -390,10 +404,8 @@ def _setup_new_table(self, table_name, containers):
if table_name.startswith("/"):
raise ValueError("Table name must not start with '/'")

table_path = PurePath(self._group) / PurePath(table_name)
table_group = str(table_path.parent)
table_basename = table_path.stem
table_path = str(table_path)
table_path = f"{self._group.rstrip('/')}/{table_name}"
table_group, table_basename = split_h5path(table_path)

for container in containers:
meta.update(container.meta) # copy metadata from container
Expand Down
1 change: 1 addition & 0 deletions docs/changes/2319.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix HDF5Writer not working on windows due to using pathlib for hdf5 dataset names.