Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@
attribute set in `RTDCBase.__init__` (#421)
- fix: `Export.fcs` and `Export.tsv` added the "dclab version" key to
the `meta_data` dictionary passed by the caller (#422)
- fix: deprecated `export.hdf5_autocomplete_config` raised an
AttributeError when given a path (`.close()` was called on the path
instead of on the file opened by `RTDCWriter`) (#423)
0.74.0
- fix: CLI commands compress, condense, join, and repack deleted the
input file if it was also given as the output path
Expand Down
12 changes: 3 additions & 9 deletions dclab/rtdc_dataset/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import uuid
import warnings

import h5py
import hdf5plugin

try:
Expand Down Expand Up @@ -932,13 +931,8 @@ def hdf5_autocomplete_config(path_or_h5obj):
"the dclab.RTDCWriter context manager or the "
"dclab.RTDCWriter.rectify_metadata function.",
DeprecationWarning)
if not isinstance(path_or_h5obj, h5py.File):
close = True
else:
close = False

hw = RTDCWriter(path_or_h5obj, mode="append")
hw.rectify_metadata()

if close:
path_or_h5obj.close()
# Only closes the file if `path_or_h5obj` is a path (an h5py.File
# passed by the caller is left open).
hw.close()
27 changes: 26 additions & 1 deletion tests/test_rtdc_export_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import dclab
from dclab import dfn, new_dataset, RTDCWriter
from dclab.rtdc_dataset import rtdc_copy, writer
from dclab.rtdc_dataset import export, rtdc_copy, writer
from dclab.rtdc_dataset.export import (
ContourNotExportedWarning,
store_filtered_feature,
Expand Down Expand Up @@ -1418,3 +1418,28 @@ def test_hdf5_traces_filter2():
assert np.all(ds["trace"]["fl1_raw"][3] == ds2["trace"]["fl1_raw"][0])
assert np.all(ds["trace"]["fl1_raw"][5] == ds2["trace"]["fl1_raw"][1])
assert np.all(ds["trace"]["fl1_raw"][6] == ds2["trace"]["fl1_raw"][2])


@pytest.mark.parametrize("path_type", [str, pathlib.Path, "h5py"])
def test_hdf5_autocomplete_config_deprecated(tmp_path, path_type):
"""The deprecated `hdf5_autocomplete_config` works with paths"""
path = tmp_path / "test.rtdc"
with dclab.RTDCWriter(path) as hw:
hw.store_metadata({"experiment": {"sample": "test",
"run index": 1}})
hw.store_feature("deform", np.linspace(0.01, 0.1, 10))
with h5py.File(path, "a") as h5:
del h5.attrs["experiment:event count"]

if path_type == "h5py":
with h5py.File(path, "a") as h5:
with pytest.warns(DeprecationWarning, match="deprecated"):
export.hdf5_autocomplete_config(h5)
# the file object passed by the user is not closed
assert h5.id.valid
else:
with pytest.warns(DeprecationWarning, match="deprecated"):
export.hdf5_autocomplete_config(path_type(path))

with h5py.File(path, "r") as h5:
assert h5.attrs["experiment:event count"] == 10
Loading