diff --git a/CHANGELOG.md b/CHANGELOG.md index fa8f91f56..7e503c88b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # PyNWB Changelog +## PyNWB 2.3.1 (February 24, 2023) + +### Bug fixes +- Fixed an issue where NWB files with version "2.0b" could not be read. @rly [#1651](https://github.com/NeurodataWithoutBorders/pynwb/pull/1651) + ## PyNWB 2.3.0 (February 23, 2023) ### Enhancements and minor changes diff --git a/src/pynwb/io/utils.py b/src/pynwb/io/utils.py index bb1f4957f..23b41b6b4 100644 --- a/src/pynwb/io/utils.py +++ b/src/pynwb/io/utils.py @@ -13,6 +13,9 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, .. If the "nwb_version" attribute on the root builder equals "2.5.1-alpha" and include_prerelease=True, then (2, 5, 1, "alpha") is returned. + If the "nwb_version" attribute == "2.0b" (the only deviation from semantic versioning in the 2.x series), then + if include_prerelease=True, (2, 0, 0, "b") is returned; else, (2, 0, 0) is returned. + :param builder: Any builder within an NWB file. :type builder: Builder :param include_prerelease: Whether to include prerelease information in the returned tuple. @@ -28,6 +31,12 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, .. nwb_version = root_builder.attributes.get("nwb_version") if nwb_version is None: raise ValueError("'nwb_version' attribute is missing from the root of the NWB file.") + # handle special non-semver case + if nwb_version == "2.0b": + if not include_prerelease: + return (2, 0, 0) + else: + return (2, 0, 0, "b") nwb_version_match = re.match(r"(\d+\.\d+\.\d+)", nwb_version)[0] # trim off any non-numeric symbols at end version_list = [int(i) for i in nwb_version_match.split(".")] if include_prerelease: diff --git a/tests/integration/utils/test_io_utils.py b/tests/integration/utils/test_io_utils.py index e712bb557..73732924f 100644 --- a/tests/integration/utils/test_io_utils.py +++ b/tests/integration/utils/test_io_utils.py @@ -46,3 +46,10 @@ def test_get_nwb_version_prerelease_true2(self): builder1 = GroupBuilder(name="root") builder1.set_attribute(name="nwb_version", value="2.0.0-alpha.sha-test.5114f85") assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "alpha.sha-test.5114f85") + + def test_get_nwb_version_20b(self): + """Get the NWB version from a builder where version == "2.0b".""" + builder1 = GroupBuilder(name="root") + builder1.set_attribute(name="nwb_version", value="2.0b") + assert get_nwb_version(builder1) == (2, 0, 0) + assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "b")