Skip to content

Commit 9f0464b

Browse files
committed
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.
1 parent 387f80b commit 9f0464b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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)