diff --git a/CHANGELOG.md b/CHANGELOG.md index 7351d30a8..50f721cc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # PyNWB Changelog +## Unreleased + +### Fixed +- Fixed parsing of the nwb_version attribute which followed the previous suggestion to have a `NWB-` prefix. + @t-b [#2118](https://github.com/NeurodataWithoutBorders/pynwb/pull/2118) + ## PyNWB 3.1.1 (July 22, 2025) ### Bug fixes diff --git a/src/pynwb/__init__.py b/src/pynwb/__init__.py index fbaa77bd2..3dfef28ff 100644 --- a/src/pynwb/__init__.py +++ b/src/pynwb/__init__.py @@ -297,7 +297,7 @@ def get_nwbfile_version(**kwargs): nwb_version_string = nwb_version_string.decode() # Parse the version string - nwb_version_parts = nwb_version_string.replace("-", ".").replace("_", ".").split(".") + nwb_version_parts = nwb_version_string.replace("NWB-", "").replace("-", ".").replace("_", ".").split(".") nwb_version = tuple([int(i) if i.isnumeric() else i for i in nwb_version_parts]) return nwb_version_string, nwb_version diff --git a/src/pynwb/io/utils.py b/src/pynwb/io/utils.py index e607b9589..6c972efda 100644 --- a/src/pynwb/io/utils.py +++ b/src/pynwb/io/utils.py @@ -37,6 +37,8 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, .. return (2, 0, 0) else: return (2, 0, 0, "b") + + nwb_version = nwb_version.removeprefix("NWB-") 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 7f36e5474..38850203e 100644 --- a/tests/integration/utils/test_io_utils.py +++ b/tests/integration/utils/test_io_utils.py @@ -57,6 +57,13 @@ def test_get_nwb_version_20b(self): assert get_nwb_version(builder1) == (2, 0, 0) assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "b") + def test_get_nwb_version_NWB_prefix(self): + """Get the NWB version from a builder where version == "NWB-2.1.3".""" + builder1 = GroupBuilder(name="root") + builder1.set_attribute(name="nwb_version", value="NWB-2.1.3") + assert get_nwb_version(builder1) == (2, 1, 3) + assert get_nwb_version(builder1, include_prerelease=False) == (2, 1, 3) + class TestGetNWBBackend(TestCase): def setUp(self): self.nwbfile = NWBFile(session_description='a test NWB File',