Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nwb_version as a fixed-length string #1669

Merged
merged 4 commits into from
Mar 17, 2023
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# PyNWB Changelog


## PyNWB 2.3.2 (Upcoming)

### Enhancements and minor changes
- Fixed typos and added codespell GitHub action to check spelling in the future. @yarikoptic [#1648](https://github.com/NeurodataWithoutBorders/pynwb/pull/1648)

### Bug fixes
- Fixed bug in ``NWBHDF5IO.nwb_version`` property to support files written by third-party software with a fixed-length ``nwb_version`` attribute. @oruebel [#1669](https://github.com/NeurodataWithoutBorders/pynwb/pull/1669)

## PyNWB 2.3.1 (February 24, 2023)

### Bug fixes
Expand Down
5 changes: 5 additions & 0 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ def nwb_version(self):
# or when the HDF5 file is not a valid NWB file
except KeyError:
return None, None
# Other system may have written nwb_version as a fixed-length string, resulting in a numpy.bytes_ object
# on read, rather than a variable-length string. To address this, decode the bytes if necessary.
if not isinstance(nwb_version_string, str):
nwb_version_string = nwb_version_string.decode()

# Parse the version string
nwb_version_parts = nwb_version_string.replace("-", ".").replace("_", ".").split(".")
nwb_version = tuple([int(i) if i.isnumeric() else i
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/hdf5/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ def test_nwb_version_property(self):
del io.attrs['nwb_version']
with NWBHDF5IO(self.path, 'r') as io:
self.assertTupleEqual(io.nwb_version, (None, None))
# check that it works when setting the attribute to a fixed-length numpy-bytes string
with File(self.path, mode='a') as io:
io.attrs['nwb_version'] = np.asarray("2.0.5", dtype=np.bytes_)[()]
with NWBHDF5IO(self.path, 'r') as io:
self.assertTupleEqual(io.nwb_version, ("2.0.5", (2, 0, 5)))

def test_check_nwb_version_ok(self):
"""Test that opening a current NWBFile passes the version check"""
Expand Down