diff --git a/CHANGELOG b/CHANGELOG index d781611a..c6352a6f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -261,6 +261,9 @@ `KernelDensityEstimationForEmtpyArrayWarning` to `KernelDensityEstimationForEmptyArrayWarning` (the old names are deprecated aliases) (#420) + - fix: `RTDC_Dict` did not allow "file" basins, because the class + attribute `_local_basins_allowed` was shadowed by the instance + attribute set in `RTDCBase.__init__` (#421) 0.74.0 - fix: CLI commands compress, condense, join, and repack deleted the input file if it was also given as the output path diff --git a/dclab/rtdc_dataset/fmt_dict.py b/dclab/rtdc_dataset/fmt_dict.py index 1f1ec11f..a1667453 100644 --- a/dclab/rtdc_dataset/fmt_dict.py +++ b/dclab/rtdc_dataset/fmt_dict.py @@ -36,8 +36,6 @@ def shape(self): class RTDC_Dict(RTDCBase): - _local_basins_allowed = True - def __init__(self, ddict, *args, **kwargs): """Dictionary-based RT-DC dataset @@ -61,6 +59,11 @@ def __init__(self, ddict, *args, **kwargs): super().__init__(*args, **kwargs) + # The data are in memory on the user's computer, so local basins + # are allowed (must be set after `RTDCBase.__init__`, which sets + # this instance attribute to False). + self._local_basins_allowed = True + t = time.localtime() # Get an identifying string diff --git a/tests/test_rtdc_fmt_dict.py b/tests/test_rtdc_fmt_dict.py index 8c786fc0..f4f49551 100644 --- a/tests/test_rtdc_fmt_dict.py +++ b/tests/test_rtdc_fmt_dict.py @@ -1,7 +1,10 @@ """Test dictionary format""" +import warnings + import numpy as np -from dclab import new_dataset +from dclab import new_dataset, RTDCWriter +from dclab.rtdc_dataset.core import LocalBasinForbiddenWarning import pytest @@ -33,6 +36,29 @@ def test_image_not_available(): assert "image" not in ds +def test_local_basins_allowed(tmp_path): + """RTDC_Dict allows "file" basins (data are on the user's computer)""" + path_basin = tmp_path / "basin.rtdc" + with RTDCWriter(path_basin) as hw: + hw.store_metadata({"experiment": {"sample": "basin", + "run index": 1}}) + hw.store_feature("deform", np.linspace(0.01, 0.1, 10)) + ddict = {"area_um": np.linspace(10, 100, 10)} + ds = new_dataset(ddict) + bdict = {"name": "local file", + "type": "file", + "format": "hdf5", + "paths": [str(path_basin)], + "features": ["deform"], + } + # RTDC_Dict does not define basins itself + ds.basins_get_dicts = lambda: [bdict] + with warnings.catch_warnings(): + warnings.simplefilter("error", LocalBasinForbiddenWarning) + assert "deform" in ds + assert np.allclose(ds["deform"], np.linspace(0.01, 0.1, 10)) + + def test_min_max_update(): ddict = example_data_dict(size=67, keys=["area_um", "deform"]) ds = new_dataset(ddict)