Skip to content

Commit

Permalink
Increase stacklevel of timezone warning (#1641)
Browse files Browse the repository at this point in the history
Co-authored-by: mavaylon1 <[email protected]>
Co-authored-by: Ryan Ly <[email protected]>
  • Loading branch information
3 people authored Feb 22, 2023
1 parent 494e288 commit b7cdead
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Added ``NWBHDF5IO.nwb_version`` property to get the NWB version from an NWB HDF5 file @oruebel [#1612](https://github.com/NeurodataWithoutBorders/pynwb/pull/1612)
- 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)
- 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)
- 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)

### Documentation and tutorial enhancements:
- 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)
Expand Down
2 changes: 1 addition & 1 deletion src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def _add_missing_timezone(date):
if not isinstance(date, datetime):
raise ValueError("require datetime object")
if date.tzinfo is None:
warn("Date is missing timezone information. Updating to local timezone.")
warn("Date is missing timezone information. Updating to local timezone.", stacklevel=2)
return date.replace(tzinfo=tzlocal())
return date

Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pynwb import NWBFile, TimeSeries, NWBHDF5IO
from pynwb.base import Image, Images
from pynwb.file import Subject, ElectrodeTable
from pynwb.file import Subject, ElectrodeTable, _add_missing_timezone
from pynwb.epoch import TimeIntervals
from pynwb.ecephys import ElectricalSeries
from pynwb.testing import TestCase, remove_test_file
Expand Down Expand Up @@ -561,3 +561,9 @@ def test_reftime_tzaware(self):
'TEST124',
self.start_time,
timestamps_reference_time=self.ref_time_notz)


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))

0 comments on commit b7cdead

Please sign in to comment.