Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/pynwb/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/utils/test_io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading