Support validation for unspecified dtype#816
Merged
ehennestad merged 22 commits intomainfrom Apr 21, 2026
Merged
Conversation
Added docstring Added arguments block with input validation Use type map for conversion to MATLAB type for basic dtype
Cleanup/simplify
Use try/catch for better efficiency
Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds proper validation for datasets whose schema omits dtype (HDMF/NWB “any dtype” behavior), while preventing duplicate dtype validation generation for included typed datasets.
Changes:
- Introduces “any dtype” runtime validation in
types.util.checkDtypeand wires it into several generatedvalidate_datamethods. - Refactors dtype mapping to a centralized basic-dtype map (
spec.getBasicDTypeMap) and updates codegen to use askip_dtype_validationflag rather than ad hocdtypehandling. - Updates/extends unit tests to cover “any dtype”, included typed dataset handling, and nested unwrap/rewrap behavior.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
+types/+util/unwrapValue.m |
Adds nested unwrapping behavior for types.untyped.Anon wrappers. |
+types/+util/rewrapValue.m |
Adds nested rewrapping behavior for types.untyped.Anon wrappers. |
+types/+util/checkDtype.m |
Adds “dtype=any” validation logic, including compound/reference/link handling. |
+types/+hdmf_experimental/HERD.m |
Updates expected index dtypes to uint8 in validators. |
+types/+hdmf_common/VectorData.m |
Adds dtype='any' validation for data. |
+types/+hdmf_common/Data.m |
Adds dtype='any' validation for data. |
+types/+hdmf_common/CSRMatrix.m |
Adds dtype='any' validation for data; updates index dtypes to uint8. |
+types/+core/TimeSeries.m |
Adds dtype='any' validation for data. |
+types/+core/ScratchData.m |
Adds dtype='any' validation for data. |
+types/+core/NWBData.m |
Adds dtype='any' validation for data. |
+types/+core/BaseImage.m |
Adds dtype='any' validation for data. |
+tests/+unit/dynamicTableTest.m |
Adjusts DynamicTable-related test inputs (shape/type changes). |
+tests/+unit/+types/FunctionTests.m |
Adds unit test for nested Anon→DatasetClass unwrap/rewrap. |
+tests/+unit/+types/+validators/CheckDtypeTest.m |
Adds unit tests for dtype='any' accept/reject behavior. |
+tests/+unit/+schema/IncludedTypedDatasetValidationTest.m |
Adds tests for skip_dtype_validation behavior in schema expansion and Dataset parsing. |
+tests/+system/DynamicTableTest.m |
Adjusts system test inputs; minor comment wording update. |
+spec/getBasicDTypeMap.m |
New centralized mapping from HDMF basic dtypes to MATLAB types. |
+spec/+internal/expandFieldsInheritedByInclusion.m |
Replaces defaulting dtype to 'any' with skip_dtype_validation marker. |
+file/mapType.m |
Refactors dtype mapping to use spec.getBasicDTypeMap and improves error messaging/docs. |
+file/fillValidators.m |
Makes dtype validation generation conditional on skipDtypeValidation; removes prior “any means skip” special-case. |
+file/Dataset.m |
Adds and populates skipDtypeValidation from schema (skip_dtype_validation). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #816 +/- ##
==========================================
- Coverage 95.44% 95.41% -0.03%
==========================================
Files 203 203
Lines 7261 7368 +107
==========================================
+ Hits 6930 7030 +100
- Misses 331 338 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cell array of numerics are not supported data for a VectorData, export will fail with error id NWB:MapData:NonCellStr This test verifying a different error and should not assign invalid data
Also suppress function output from validateAnyType
Co-authored-by: Copilot <[email protected]>
Ensure validBasicTypes is a column vector
a0736d7 to
87a2d42
Compare
bendichter
approved these changes
Apr 21, 2026
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.
Motivation
This is currently allowed:
types.core.TimeSeries('data', types.core.TimeSeries())This PR adds validation for datasets where
dtypeis omitted in the schema and MatNWB therefore allows any valid dtype. The main goal is to support the HDMF/NWB spec behavior for unspecifieddtypewhile still validating that provided values are valid basic, reference, soft link, or compound values.It also removes the earlier ad hoc use of
dtypeas a generator control flag for included typed datasets. Instead, included typed datasets now carry an internalskip_dtype_validationmarker so duplicate dtype validation is not generated when the including dataset omitsdtype.How to test the behavior?
Before:
After:
Relevant unittests
Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Codex