Skip to content

Commit b7cdead

Browse files
CodyCBakerPhDmavaylon1rly
authored
Increase stacklevel of timezone warning (#1641)
Co-authored-by: mavaylon1 <[email protected]> Co-authored-by: Ryan Ly <[email protected]>
1 parent 494e288 commit b7cdead

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Added ``NWBHDF5IO.nwb_version`` property to get the NWB version from an NWB HDF5 file @oruebel [#1612](https://github.com/NeurodataWithoutBorders/pynwb/pull/1612)
1414
- Updated ``NWBHDF5IO.read`` to check NWB version before read and raise more informative error if an unsupported version is found @oruebel [#1612](https://github.com/NeurodataWithoutBorders/pynwb/pull/1612)
1515
- Added the `driver` keyword argument to the `pynwb.validate` function as well as the corresponding namespace caching. @CodyCBakerPhD [#1588](https://github.com/NeurodataWithoutBorders/pynwb/pull/1588)
16+
- Increased the stacklevel of the warning from `_add_missing_timezone` in `pynwb.file` to make identification of which datetime field is missing a timezone easier. @CodyCBakerPhD [#1641](https://github.com/NeurodataWithoutBorders/pynwb/pull/1641)
1617

1718
### Documentation and tutorial enhancements:
1819
- Adjusted [ecephys tutorial](https://pynwb.readthedocs.io/en/stable/tutorials/domain/ecephys.html) to create fake data with proper dimensions @bendichter [#1581](https://github.com/NeurodataWithoutBorders/pynwb/pull/1581)

src/pynwb/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def _add_missing_timezone(date):
11201120
if not isinstance(date, datetime):
11211121
raise ValueError("require datetime object")
11221122
if date.tzinfo is None:
1123-
warn("Date is missing timezone information. Updating to local timezone.")
1123+
warn("Date is missing timezone information. Updating to local timezone.", stacklevel=2)
11241124
return date.replace(tzinfo=tzlocal())
11251125
return date
11261126

tests/unit/test_file.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from pynwb import NWBFile, TimeSeries, NWBHDF5IO
88
from pynwb.base import Image, Images
9-
from pynwb.file import Subject, ElectrodeTable
9+
from pynwb.file import Subject, ElectrodeTable, _add_missing_timezone
1010
from pynwb.epoch import TimeIntervals
1111
from pynwb.ecephys import ElectricalSeries
1212
from pynwb.testing import TestCase, remove_test_file
@@ -561,3 +561,9 @@ def test_reftime_tzaware(self):
561561
'TEST124',
562562
self.start_time,
563563
timestamps_reference_time=self.ref_time_notz)
564+
565+
566+
class TestTimezone(TestCase):
567+
def test_raise_warning__add_missing_timezone(self):
568+
with self.assertWarnsWith(UserWarning, "Date is missing timezone information. Updating to local timezone."):
569+
_add_missing_timezone(datetime(2017, 5, 1, 12))

0 commit comments

Comments
 (0)