diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af4c77bb..e52e1cbf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,13 @@ ## PyNWB 3.1.3 (Unreleased) +### Fixed +- Fixed incorrect warning for path not ending in `.nwb` when no path argument was provided. @t-b [#2130](https://github.com/NeurodataWithoutBorders/pynwb/pull/2130) + ### Documentation and tutorial enhancements - Change UI of assistant to be an accordion that is always visible. [#2124](https://github.com/NeurodataWithoutBorders/pynwb/pull/2124) + ## PyNWB 3.1.2 (August 13, 2025) ### Fixed diff --git a/src/pynwb/__init__.py b/src/pynwb/__init__.py index c39e89e04..4a11daa86 100644 --- a/src/pynwb/__init__.py +++ b/src/pynwb/__init__.py @@ -428,7 +428,7 @@ def __init__(self, **kwargs): if mode in io_modes_that_create_file or manager is not None or extensions is not None: load_namespaces = False - if mode in io_modes_that_create_file and not str(path).endswith('.nwb'): + if mode in io_modes_that_create_file and path is not None and not str(path).endswith('.nwb'): warn(f"The file path provided: {path} does not end in '.nwb'. " "It is recommended that NWB files using the HDF5 backend use the '.nwb' extension.", UserWarning) diff --git a/tests/unit/test_file.py b/tests/unit/test_file.py index 5338f6669..4656858fe 100644 --- a/tests/unit/test_file.py +++ b/tests/unit/test_file.py @@ -1,6 +1,10 @@ import numpy as np import pandas as pd +import h5py +import io +import warnings + from datetime import datetime, timedelta from dateutil.tz import tzlocal, tzutc from hdmf.common import DynamicTable @@ -711,3 +715,12 @@ class TestTimezone(TestCase): def test_raise_warning__add_missing_timezone(self): with self.assertWarnsWith(UserWarning, "Date is missing timezone information. Updating to local timezone."): _add_missing_timezone(datetime(2017, 5, 1, 12)) + +class TestNoWarningWithoutPath(TestCase): + def test_raise_warning(self): + with warnings.catch_warnings(): + warnings.simplefilter("error") + + data = io.BytesIO() + h5file = h5py.File(data, "w") + NWBHDF5IO(mode = "w", file = h5file)