Skip to content

Commit 9f2178f

Browse files
committed
BF: ignore some pynwb validation errors if file nwb_version < 2.1.0
Closes #22
1 parent de74649 commit 9f2178f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

dandi/pynwb_utils.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import h5py
2-
import pynwb
2+
import re
33
import warnings
4+
from distutils.version import LooseVersion
45

6+
import pynwb
57
from pynwb import NWBHDF5IO
68

79
from . import get_logger
@@ -95,6 +97,29 @@ def validate(path):
9597
errors = pynwb.validate(reader)
9698
except Exception as exc:
9799
errors = [f"Failed to validate {path}: {exc}"]
100+
101+
# To overcome
102+
# https://github.com/NeurodataWithoutBorders/pynwb/issues/1090
103+
# https://github.com/NeurodataWithoutBorders/pynwb/issues/1091
104+
re_ok_prior_210 = re.compile(
105+
"general/(experimenter|related_publications)\): "
106+
"incorrect shape - expected an array of shape .\[None\]."
107+
)
108+
try:
109+
version = get_nwb_version(path)
110+
except:
111+
# we just will not remove any errors
112+
pass
113+
else:
114+
if version and LooseVersion(version) < "2.1.0":
115+
errors_ = errors[:]
116+
errors = [e for e in errors if not re_ok_prior_210.search(str(e))]
117+
if errors != errors_:
118+
lgr.debug(
119+
"Filtered out %d validation errors on %s",
120+
len(errors_) - len(errors),
121+
path,
122+
)
98123
return errors
99124

100125

0 commit comments

Comments
 (0)