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

Do not auto-set timezone, allow date #1886

Merged
merged 12 commits into from
Apr 25, 2024
Merged

Do not auto-set timezone, allow date #1886

merged 12 commits into from
Apr 25, 2024

Conversation

rly
Copy link
Contributor

@rly rly commented Apr 10, 2024

Motivation

Fix #1859, fix #1843

  1. Date strings (e.g., "2024-04-10" without the "T") can now be roundtripped, so if a user writes a datetime.date object, it will be written without the "T" and read as a datetime.date object.
  2. The local timezone is no longer automatically set on a non-timezone-aware datetime
  3. timestamps_reference_time is allowed to be timezone-naive
  4. Subject date_of_birth, file session_start_time, file file_create_date, and file timestamps_reference_time now allow date in addition to datetime

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 flake8 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.

@rly rly mentioned this pull request Apr 10, 2024
11 tasks
Copy link

codecov bot commented Apr 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.01%. Comparing base (001a9fd) to head (10060e6).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1886      +/-   ##
==========================================
+ Coverage   91.81%   92.01%   +0.20%     
==========================================
  Files          27       27              
  Lines        2627     2619       -8     
  Branches      688      685       -3     
==========================================
- Hits         2412     2410       -2     
+ Misses        142      139       -3     
+ Partials       73       70       -3     
Flag Coverage Δ
integration 72.81% <100.00%> (+0.33%) ⬆️
unit 83.92% <77.77%> (+0.10%) ⬆️

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.

@rly
Copy link
Contributor Author

rly commented Apr 10, 2024

@bendichter What do you think about this approach?

bendichter
bendichter previously approved these changes Apr 11, 2024
Copy link
Contributor

@bendichter bendichter left a comment

Choose a reason for hiding this comment

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

Looks great!!! Do we still have tests that include timezones? (I'm on my phone)

@rly
Copy link
Contributor Author

rly commented Apr 11, 2024

Great, thanks. I removed the affected tests and added some tests to ensure that the following cases work:

  1. datetime with time zone
  2. datetime without time zone
  3. date

I want to add a few more tests and remove timezone from a few tests, so this is not ready to merge yet.

@bendichter
Copy link
Contributor

ok. Looks great so far!

@rly
Copy link
Contributor Author

rly commented Apr 12, 2024

I think given a dataset spec or attribute spec with dtype isodatetime, the mapping of a string value to a datetime or date object should occur in HDMF on construction of the object, rather than as a custom constructor argument override on every field that we know has an isodatetime spec. Requiring the override to get the string as a datetime or date object creates a burden on any extension that wants to store datetimes and read datetime data as datetime objects instead of as strings.

So, parse_datetime should move to HDMF's ObjectMapper. I'll create an issue on HDMF. If it takes longer to implement that than the next pynwb release, we can just merge this change and remove it later once HDMF handles the mapping.

@rly rly marked this pull request as ready for review April 24, 2024 16:48
@rly rly requested review from mavaylon1, oruebel and bendichter April 25, 2024 18:07
@rly rly merged commit ff1a03c into dev Apr 25, 2024
21 of 24 checks passed
@rly rly deleted the datetime branch April 25, 2024 18:39
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]: date of birth date time round trip Handling timezone information absence
3 participants