Add check_spatial_series_unit for SpatialSeries unit validation#685
Merged
h-mayorquin merged 10 commits intodevfrom Mar 26, 2026
Merged
Add check_spatial_series_unit for SpatialSeries unit validation#685h-mayorquin merged 10 commits intodevfrom
h-mayorquin merged 10 commits intodevfrom
Conversation
This was referenced Mar 24, 2026
for more information, see https://pre-commit.ci
Contributor
|
This is tricky since sometimes the units are really unknown or arbitrary, but I suppose that's fine if it's just a violation and not a critical. |
Add tests for unit=None and CompassDirection skip paths in check_spatial_series_unit to achieve full patch coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use 'kilometers' instead of 'degrees' so the test actually exercises the CompassDirection ancestor check rather than passing due to a valid unit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bendichter
approved these changes
Mar 25, 2026
Collaborator
Author
Maybe we can add a escape hatch of allowing them to intentionally write "n.a." in case that is the case, what do you think? |
Collaborator
Author
Contributor
|
yeah I like the idea of allowing n.a. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #685 +/- ##
==========================================
+ Coverage 79.92% 83.13% +3.21%
==========================================
Files 48 48
Lines 1878 1886 +8
==========================================
+ Hits 1501 1568 +67
+ Misses 377 318 -59
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SpatialSeries has a free-form
.unitfield that defaults to"meters"in PyNWB but accepts any string. The NWB spec says it "should be SI unit" but nothing enforces this, so files in practice contain values like"m","cm","unknown", or empty strings. This check flags unrecognized unit strings to push the ecosystem toward consistent values.The valid unit allowlist uses full SI words in plural form, matching the PyNWB convention:
"meters","centimeters","millimeters","micrometers","degrees","radians", and"pixels". I chose full words over abbreviations to be consistent with what PyNWB produces as defaults and what the existingcheck_compass_direction_unitalready expects. SI length prefixes are included following the same principle ascheck_subject_weight, which accepts the full range of SI mass prefixes (kg,g,mg, etc.).The check skips SpatialSeries objects inside a CompassDirection container since those are already covered by
check_compass_direction_unit.Related to #208 (general SI unit validation). This PR addresses one specific type rather than the broader question of enforcing SI conventions across all TimeSeries unit fields.