From 139a5ab77e9ab0c7bf56f108976354ebfe7b1837 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Sun, 10 Dec 2023 14:13:04 +0100 Subject: [PATCH 1/5] fix bug with w- io mode --- src/pynwb/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pynwb/__init__.py b/src/pynwb/__init__.py index 7cf32e074..6e3b3104f 100644 --- a/src/pynwb/__init__.py +++ b/src/pynwb/__init__.py @@ -261,7 +261,8 @@ def __init__(self, **kwargs): popargs('path', 'mode', 'manager', 'extensions', 'load_namespaces', 'file', 'comm', 'driver', 'herd_path', kwargs) # Define the BuildManager to use - if mode in 'wx' or manager is not None or extensions is not None: + io_modes_that_create_file = ['w', 'w-', 'x'] + if mode in io_modes_that_create_file or manager is not None or extensions is not None: load_namespaces = False if load_namespaces: From e8c4e3d345304fafc6b87aca9772e9aedc4ee359 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Tue, 12 Dec 2023 14:34:05 +0100 Subject: [PATCH 2/5] add test --- tests/integration/hdf5/test_io.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/integration/hdf5/test_io.py b/tests/integration/hdf5/test_io.py index 0fd790073..d04a796c6 100644 --- a/tests/integration/hdf5/test_io.py +++ b/tests/integration/hdf5/test_io.py @@ -3,6 +3,7 @@ import numpy as np from h5py import File from pathlib import Path +import tempfile from pynwb import NWBFile, TimeSeries, get_manager, NWBHDF5IO, validate @@ -14,6 +15,7 @@ from pynwb.spec import NWBGroupSpec, NWBDatasetSpec, NWBNamespace from pynwb.ecephys import ElectricalSeries, LFP from pynwb.testing import remove_test_file, TestCase +from pynwb.testing.mock.file import mock_NWBFile class TestHDF5Writer(TestCase): @@ -516,3 +518,18 @@ def test_round_trip_with_pathlib_path(self): with NWBHDF5IO(pathlib_path, 'r') as io: read_file = io.read() self.assertContainerEqual(read_file, self.nwbfile) + + +class TestNWBHDF5IOModes(TestCase): + def test_file_creation_and_deletion(self): + io_modes_that_create_file = ["w", "w-", "x"] + + with tempfile.TemporaryDirectory() as temp_dir: + temp_dir = Path(temp_dir) + for io_mode in io_modes_that_create_file: + file_path = temp_dir / f"test_io_mode={io_mode}.nwb" + + # Test file creation + nwbfile = mock_NWBFile() + with NWBHDF5IO(str(file_path), io_mode) as io: + io.write(nwbfile) From 0c075666610934d44a5e23ff623205afcf04f032 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Tue, 12 Dec 2023 14:35:35 +0100 Subject: [PATCH 3/5] move the test to the indicated place --- tests/integration/hdf5/test_io.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/integration/hdf5/test_io.py b/tests/integration/hdf5/test_io.py index d04a796c6..77e3256c4 100644 --- a/tests/integration/hdf5/test_io.py +++ b/tests/integration/hdf5/test_io.py @@ -123,6 +123,19 @@ def test_write_no_cache_spec(self): io.write(self.container, cache_spec=False) with File(self.path, 'r') as f: self.assertNotIn('specifications', f) + + def test_file_creation_io_modes(self): + io_modes_that_create_file = ["w", "w-", "x"] + + with tempfile.TemporaryDirectory() as temp_dir: + temp_dir = Path(temp_dir) + for io_mode in io_modes_that_create_file: + file_path = temp_dir / f"test_io_mode={io_mode}.nwb" + + # Test file creation + nwbfile = mock_NWBFile() + with NWBHDF5IO(str(file_path), io_mode) as io: + io.write(nwbfile) class TestHDF5WriterWithInjectedFile(TestCase): @@ -519,17 +532,3 @@ def test_round_trip_with_pathlib_path(self): read_file = io.read() self.assertContainerEqual(read_file, self.nwbfile) - -class TestNWBHDF5IOModes(TestCase): - def test_file_creation_and_deletion(self): - io_modes_that_create_file = ["w", "w-", "x"] - - with tempfile.TemporaryDirectory() as temp_dir: - temp_dir = Path(temp_dir) - for io_mode in io_modes_that_create_file: - file_path = temp_dir / f"test_io_mode={io_mode}.nwb" - - # Test file creation - nwbfile = mock_NWBFile() - with NWBHDF5IO(str(file_path), io_mode) as io: - io.write(nwbfile) From ef69a7cb05ad964bdd48577a6f8f68a9ff4be285 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Tue, 12 Dec 2023 14:37:58 +0100 Subject: [PATCH 4/5] flake --- tests/integration/hdf5/test_io.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/hdf5/test_io.py b/tests/integration/hdf5/test_io.py index 77e3256c4..d68334c89 100644 --- a/tests/integration/hdf5/test_io.py +++ b/tests/integration/hdf5/test_io.py @@ -123,7 +123,7 @@ def test_write_no_cache_spec(self): io.write(self.container, cache_spec=False) with File(self.path, 'r') as f: self.assertNotIn('specifications', f) - + def test_file_creation_io_modes(self): io_modes_that_create_file = ["w", "w-", "x"] @@ -531,4 +531,3 @@ def test_round_trip_with_pathlib_path(self): with NWBHDF5IO(pathlib_path, 'r') as io: read_file = io.read() self.assertContainerEqual(read_file, self.nwbfile) - From c3dcf87afcbeb44ccf5ba3b04a69a88b24d806c1 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Wed, 13 Dec 2023 22:32:23 -0800 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd4dbfd05..09bc731e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ - Updated timeseries data checks to warn instead of error when reading invalid files. @stephprince [#1793](https://github.com/NeurodataWithoutBorders/pynwb/pull/1793) - Expose the offset, conversion and channel conversion parameters in `mock_ElectricalSeries`. @h-mayorquin [#1796](https://github.com/NeurodataWithoutBorders/pynwb/pull/1796) +### Bug fixes +- Fix bug where namespaces were loaded in "w-" mode. @h-mayorquin [#1795](https://github.com/NeurodataWithoutBorders/pynwb/pull/1795) + ## PyNWB 2.5.0 (August 18, 2023) ### Enhancements and minor changes