Skip to content

Commit

Permalink
fix: metadata of tables not copied by copier.py
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 5, 2025
1 parent b39dfaa commit 81ca54c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.62.8
- fix: metadata of tables not copied by `copier.py`
- docs: formatting typo (#270)
0.62.7
- fix: IntegrityChecker must not load basins
Expand Down
9 changes: 4 additions & 5 deletions dclab/rtdc_dataset/copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def rtdc_copy(src_h5file: h5py.Group,
Add this prefix to the name of the logs and tables in `dst_h5file`.
"""
# metadata
for akey in src_h5file.attrs:
dst_h5file.attrs[akey] = src_h5file.attrs[akey]
dst_h5file.attrs.update(src_h5file.attrs)

# events in source file
if "events" in src_h5file:
Expand Down Expand Up @@ -84,11 +83,12 @@ def rtdc_copy(src_h5file: h5py.Group,
# dst_loc=dst_h5file["tables"],
# dst_name=meta_prefix + tkey,
# recursive=False)
dst_h5file["tables"].create_dataset(
copy_table = dst_h5file["tables"].create_dataset(
name=tkey,
data=src_h5file["tables"][tkey][:],
fletcher32=True,
**hdf5plugin.Zstd(clevel=5))
copy_table.attrs.update(src_h5file["tables"][tkey].attrs)

# events
if isinstance(features, list):
Expand Down Expand Up @@ -303,8 +303,7 @@ def h5ds_copy(src_loc, src_name, dst_loc, dst_name=None,
for chunk in src.iter_chunks():
dst[chunk] = src[chunk]
# Also write all the attributes
for key in src.attrs:
dst.attrs[key] = src.attrs[key]
dst.attrs.update(src.attrs)
else:
# Copy the Dataset to the destination as-is.
h5py.h5o.copy(src_loc=src_loc.id,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_rtdc_copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ def test_copy_tables_hdf5_issue_3214():
rtdc_copy(src_h5file=h5,
dst_h5file=hc)

# Also make sure metadata are copied
with h5py.File(path_copy) as hc:
assert hc["tables"]["cytoshot_monitor"].attrs["COLOR_shift"]\
== "#0e8f69"


def test_copy_with_compression():
path = retrieve_data("fmt-hdf5_image-bg_2020.zip")
Expand Down

0 comments on commit 81ca54c

Please sign in to comment.