Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow timezone-naive timestamps reference time on read #2056

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

stephprince
Copy link
Contributor

@stephprince stephprince commented Mar 10, 2025

Motivation

Fix #2054. Allow files with a timestamps reference time that is not timezone-aware to be read.

How to test the behavior?

In MATLAB:

nwb = NwbFile( ...
    'session_description', 'Simple demo file', ...
    'identifier', 'test_file', ...
    'session_start_time', datetime("now"), ...
    'timestamps_reference_time', datetime("now"));
nwbExport(nwb, 'temp.nwb')

In python:

from pynwb import NWBHDF5IO

io = NWBHDF5IO('temp.nwb', mode="r")
nwbfile = io.read()

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Have you checked our Contributing document?
  • Have you ensured the PR clearly describes the problem and the solution?
  • Is your contribution compliant with our coding style? This can be checked running ruff check . && codespell from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using "Fix #XXX" notation where XXX is the issue number? By including "Fix #XXX" you allow GitHub to close issue #XXX when the PR is merged.

@@ -491,7 +491,9 @@ def __init__(self, **kwargs):
if timestamps_reference_time is None:
args_to_set['timestamps_reference_time'] = args_to_set['session_start_time']
elif timestamps_reference_time.tzinfo is None:
raise ValueError("'timestamps_reference_time' must be a timezone-aware datetime object.")
self._error_on_new_pass_on_construct(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that timezone information is automatically added to session_start_time if it is missing. Instead of throwing an error, would it be better to also automatically add timezone information to timestamps_reference_time if missing?

Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.85%. Comparing base (2888ad0) to head (9f03c11).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2056   +/-   ##
=======================================
  Coverage   92.85%   92.85%           
=======================================
  Files          28       28           
  Lines        2756     2756           
  Branches      716      716           
=======================================
  Hits         2559     2559           
  Misses        127      127           
  Partials       70       70           
Flag Coverage Δ
integration 73.69% <0.00%> (ø)
unit 82.76% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stephprince stephprince marked this pull request as ready for review March 12, 2025 23:56
@stephprince stephprince requested a review from rly March 12, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Fail to read NWB file where TimeZone is missing from session_start_time
1 participant