Skip to content

Commit

Permalink
fix: some datasets with unknown feature names could not be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Mar 29, 2021
1 parent e8e0d88 commit 813ab61
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,4 +1,6 @@
0.33.2
- fix: some datasets with unknown feature names could not be
opened (AssertionError regression in 0.33.1)
- fix: workaround for sporadic JSONDecodeError when accessing DCOR
- ref: cleanup cli.py
- ref: cleanup util.py and deprecate `hash_class` argument in
Expand Down
17 changes: 8 additions & 9 deletions dclab/rtdc_dataset/fmt_hdf5.py
Expand Up @@ -62,14 +62,7 @@ def __init__(self, h5):
self._features.remove("trace")

def __contains__(self, key):
if self._is_defective_feature(key):
contained = False
else:
if key in self._features and dfn.feature_exists(key):
contained = True
else:
contained = False
return contained
return key in self.keys()

def __getitem__(self, key):
# user-level checking is done in core.py
Expand Down Expand Up @@ -104,10 +97,16 @@ def _is_defective_feature(self, key):
return defective

def keys(self):
"""Returns list of valid features
Checks for
- defective features
- existing feature names
"""
features = []
for key in self._features:
# check for defective features
if not self._is_defective_feature(key):
if dfn.feature_exists(key) and not self._is_defective_feature(key):
features.append(key)
return features

Expand Down
11 changes: 11 additions & 0 deletions tests/test_rtdc_fmt_hdf5.py
Expand Up @@ -127,6 +127,17 @@ def test_no_suffix():
assert(len(ds) == 8)


def test_open_with_invalid_feature_names():
"""Loading an .rtdc file that has wrong feature name"""
path = str(retrieve_data("rtdc_data_hdf5_mask_contour.zip"))
# add wrong feature name right at the top of the list
with h5py.File(path, "r+") as h5:
h5["events"]["a0"] = h5["events"]["deform"]
# see if we can open the file without any error
ds = new_dataset(path)
assert len(ds) == 8


@pytest.mark.filterwarnings(
'ignore::dclab.rtdc_dataset.config.UnknownConfigurationKeyWarning')
def test_trace():
Expand Down

0 comments on commit 813ab61

Please sign in to comment.