Require timezone information for isodatetime validation#1399
Require timezone information for isodatetime validation#1399rly merged 39 commits intohdmf-dev:devfrom
Conversation
|
Thank you @sejalpunwatkar . Please add tests to verify that your fix worked. The tests should fail prior to this change and succeed with this change. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1399 +/- ##
==========================================
+ Coverage 92.83% 92.84% +0.01%
==========================================
Files 41 41
Lines 9958 9986 +28
Branches 2039 2052 +13
==========================================
+ Hits 9245 9272 +27
Misses 436 436
- Partials 277 278 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the feedback, @rly . I will add unit tests to tests/unit/test_validator.py (or the relevant test suite) that include ISO datetime strings both with and without timezones to ensure the new validation logic triggers correctly and prevents regressions. |
|
Thanks @sejalpunwatkar . This is looking good. Can you also add a test for validating DatasetSpec with dtype=isodatetime? |
|
Ideally the tests in each PR cover each change made in the PR. You can look at the codecov report above to see what lines were not touched by the tests. It's easy for a bug to appear if the code isn't tested. |
|
When you're done, could you please also add an entry to the CHANGELOG.md for version 5.0.0 with a brief description of the change. Follow the format of the other changelog entries. This would go under "Fixed" |
|
Thanks for the detailed feedback @rly ! I’ll get started on these updates right away, including the 'Z' suffix test, the DatasetSpec validation, and the CHANGELOG entry. I'll also make sure to hit the missing lines to get that Codecov report back to green. |
|
Updates made:
Added tests for:
All tests are passing locally. |
There was a problem hiding this comment.
Pull request overview
This PR adds timezone validation for isodatetime values to address issue #1284, which reported that the validator doesn't raise warnings when datetime values lack required timezone information.
Changes:
- Added
has_timezone()helper function to detect timezone presence in ISO datetime strings - Integrated timezone validation into
AttributeValidatorandDatasetValidator - Added test cases for scalar datetime strings with and without timezone information
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| src/hdmf/validate/validator.py | Added has_timezone() helper function and integrated timezone checks in AttributeValidator and DatasetValidator to raise Error when isodatetime strings lack timezone information |
| tests/unit/validator_tests/test_validate.py | Added TestISODateTimeTimezone and TestISODateTimeDatasetTimezone test classes to verify timezone validation for attributes and datasets with scalar datetime strings |
| CHANGELOG.md | Added entry documenting the fix for missing timezone validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for the updates @sejalpunwatkar . Could you please address the issues raised by copilot? They are mostly the same issue. I do think we need to test arrays of datetimes, that checking for "+"/"-" can lead to false positives, and that the variable names could be made clearer. The arrays issue is causing a test failure in the pynwb tests. Any existing hdmf test(s) where a datetime without time zone is used should be updated because that is not valid. Thank you! |
|
Updated validator.py to enforce that isodatetime datasets include timezone information.
|
|
@sejalpunwatkar thanks for the updates! We are in a bit of crunch this week so it'll likely be later next week before we get back to this on our end. Feel free to re-ping at the end of next week if you have not seen activity here. |
|
No problem at all, @oruebel . I appreciate the update! I'll use this time to verify that every test runs smoothly and keep the PR ready for your review. I'll re-ping you at the end of next week as suggested. Hope the crunch goes well! |
a724ae8 to
fe9207b
Compare
| class TestISODateTimeTimezone(ValidatorTestBase): | ||
| """Test that isodatetime dtype requires timezone information.""" |
There was a problem hiding this comment.
| class TestISODateTimeTimezone(ValidatorTestBase): | |
| """Test that isodatetime dtype requires timezone information.""" | |
| class TestISODateTimeAttributeTimezone(ValidatorTestBase): | |
| """Test that an AttributeSpec with isodatetime dtype requires timezone information.""" |
| self.assertIsInstance(result[0], Error) | ||
|
|
||
| class TestISODateTimeDatasetTimezone(ValidatorTestBase): | ||
| """Test that isodatetime dtype in DatasetSpec requires timezone information.""" |
There was a problem hiding this comment.
| """Test that isodatetime dtype in DatasetSpec requires timezone information.""" | |
| """Test that a DatasetSpec with isodatetime spec requires timezone information.""" |
|
Hi @rly , I've addressed all the feedback and pushed the updates: |
for more information, see https://pre-commit.ci
Removed unnecessary blank lines in the validator.py file.
for more information, see https://pre-commit.ci
…mensional support
|
No worries at all, @rly ! I really appreciate the detailed feedback and the opportunity to make the code cleaner and more robust. It’s been a great learning process.
|
|
Looks good @sejalpunwatkar ! I made a couple minor changes. One last comment: |
2959999 to
3c58402
Compare
|
Hi @rly , I've finished the refactor! I ran into some merge conflicts earlier which have now been resolved. The tests are passing locally (1659 passed), and the code is now unified into a single class with the shared helper as requested. Ready for another look! |
rly
left a comment
There was a problem hiding this comment.
Looks good. Thank you for your sustained effort on this @sejalpunwatkar !
|
Thank you, @rly ! I appreciate the support in getting this across the finish line. Looking forward to helping out with more issues soon. |
This PR adds validation to ensure that values with string_format="isodatetime" include timezone information.
Specifically:
Added a has_timezone() helper function to detect timezone presence.
Integrated timezone validation in both AttributeValidator and DatasetValidator.
Raises a validation Error if an ISO datetime string is missing timezone information.
Existing type and shape validation behavior remains unchanged.
Please let me know if enforcing timezone as a requirement aligns with the intended specification behavior.
Fix #1284