Skip to content

Commit

Permalink
enh: increase verbosity for unreachable remote basin features
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 5, 2024
1 parent 51c3adc commit d34f2f1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(minor speedup since previously a chunk size of 100 events was used
for images and scalar features were written in one big chunk)
- enh: favor array operations in `yield_filtered_array_stacks` (~4x speed-up)
- enh: increase verbosity for unreachable remote basin features
- ref: implement `__array__` methods for hierarchy event classes
- ref: implement `__array__` method for `H5MaskEvent`
- ref: new submodule for hierarchy format
Expand Down
6 changes: 6 additions & 0 deletions dclab/rtdc_dataset/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def __getitem__(self, feat):
data = self._get_ancillary_feature_data(feat)
if data is not None:
return data
if feat in self:
warnings.warn(f"The feature {feat} is supposedly defined in "
f"{self}, but I cannot get its data. Please "
f"make sure you have not defined any unreachable "
f"remote basins.",
UserWarning)
# Not here ¯\_(ツ)_/¯
raise KeyError(f"Feature '{feat}' does not exist in {self}!")

Expand Down
8 changes: 7 additions & 1 deletion tests/test_rtdc_fmt_dcor_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ def test_create_basin_file_non_matching_identifier(tmp_path):
assert ds.features_basin == ["deform"]
# ...but it is actually not, since the run identifier does not match
# and therefore dclab does not allow the user to access it.
with pytest.raises(KeyError, match="deform"):
#
# Until a workaround is found for invalid basin URLs that return a
# status code of 200, do this test which should raise a warning,
# because `__contains__` returns True for "trace", but the trace data
# are nowhere to find.
with (pytest.warns(UserWarning, match="but I cannot get its data"),
pytest.raises(KeyError, match="deform")):
_ = ds["deform"]


Expand Down
32 changes: 32 additions & 0 deletions tests/test_rtdc_fmt_http_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,35 @@ def test_trace_availability(tmp_path):
ds.filter.manual[0] = False
ds2 = dclab.new_dataset(ds)
assert "trace" in ds2


def test_trace_availability_invalid(tmp_path):
h5path = tmp_path / "test_basin_http.rtdc"

with h5py.File(h5path, "a") as dst, RTDC_HTTP(http_url) as src:
# Store non-existent basin information
bdat = {
"type": "remote",
"format": "http",
"urls": ["https://dcor.mpl.mpg.de/api/3/action/site_read"],
"features": ["trace"],
}
blines = json.dumps(bdat, indent=2).split("\n")
basins = dst.require_group("basins")
with RTDCWriter(dst, mode="append") as hw:
hw.write_text(basins, "my_basin", blines)
meta = src.config.as_dict(pop_filtering=True)
hw.store_metadata(meta)

ds = dclab.new_dataset(h5path)
ds.filter.manual[:] = False
ds.filter.manual[:2] = True
ds.apply_filter()
assert "trace" in ds
# Until a workaround is found for invalid basin URLs that return a
# status code of 200, do this test which should raise a warning,
# because `__contains__` returns True for "trace", but the trace data
# are nowhere to find.
with (pytest.warns(UserWarning, match="but I cannot get its data"),
pytest.raises(KeyError, match="trace")):
dclab.new_dataset(ds)

0 comments on commit d34f2f1

Please sign in to comment.