Skip to content

Commit d3e4085

Browse files
t-bstephprince
andauthored
NWBHDF5IO: Don't check path if it is None (#2130)
* NWBHDF5IO: Don't check path if it is None We only need to check if the given path ends in .nwb if it is not None. * update CHANGELOG --------- Co-authored-by: Steph Prince <[email protected]>
1 parent 387f80b commit d3e4085

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
## PyNWB 3.1.3 (Unreleased)
44

5+
### Fixed
6+
- 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)
7+
58
### Documentation and tutorial enhancements
69
- Change UI of assistant to be an accordion that is always visible. [#2124](https://github.com/NeurodataWithoutBorders/pynwb/pull/2124)
710

11+
812
## PyNWB 3.1.2 (August 13, 2025)
913

1014
### Fixed

src/pynwb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def __init__(self, **kwargs):
428428
if mode in io_modes_that_create_file or manager is not None or extensions is not None:
429429
load_namespaces = False
430430

431-
if mode in io_modes_that_create_file and not str(path).endswith('.nwb'):
431+
if mode in io_modes_that_create_file and path is not None and not str(path).endswith('.nwb'):
432432
warn(f"The file path provided: {path} does not end in '.nwb'. "
433433
"It is recommended that NWB files using the HDF5 backend use the '.nwb' extension.", UserWarning)
434434

tests/unit/test_file.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import numpy as np
22
import pandas as pd
33

4+
import h5py
5+
import io
6+
import warnings
7+
48
from datetime import datetime, timedelta
59
from dateutil.tz import tzlocal, tzutc
610
from hdmf.common import DynamicTable
@@ -711,3 +715,12 @@ class TestTimezone(TestCase):
711715
def test_raise_warning__add_missing_timezone(self):
712716
with self.assertWarnsWith(UserWarning, "Date is missing timezone information. Updating to local timezone."):
713717
_add_missing_timezone(datetime(2017, 5, 1, 12))
718+
719+
class TestNoWarningWithoutPath(TestCase):
720+
def test_raise_warning(self):
721+
with warnings.catch_warnings():
722+
warnings.simplefilter("error")
723+
724+
data = io.BytesIO()
725+
h5file = h5py.File(data, "w")
726+
NWBHDF5IO(mode = "w", file = h5file)

0 commit comments

Comments
 (0)