diff --git a/ctapipe/io/hdf5merger.py b/ctapipe/io/hdf5merger.py index b34e296280f..f8c6ca7aca7 100644 --- a/ctapipe/io/hdf5merger.py +++ b/ctapipe/io/hdf5merger.py @@ -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): @@ -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 diff --git a/ctapipe/io/hdf5tableio.py b/ctapipe/io/hdf5tableio.py index 606b3092b34..d54dbcad644 100644 --- a/ctapipe/io/hdf5tableio.py +++ b/ctapipe/io/hdf5tableio.py @@ -20,7 +20,7 @@ TimeColumnTransform, ) -__all__ = ["HDF5TableWriter", "HDF5TableReader"] +__all__ = ["HDF5TableWriter", "HDF5TableReader", "split_h5path"] PYTABLES_TYPE_MAP = { "float": tables.Float64Col, @@ -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] @@ -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 diff --git a/docs/changes/2319.bugfix.rst b/docs/changes/2319.bugfix.rst new file mode 100644 index 00000000000..0058fe72e24 --- /dev/null +++ b/docs/changes/2319.bugfix.rst @@ -0,0 +1 @@ +Fix HDF5Writer not working on windows due to using pathlib for hdf5 dataset names.