What happened?
MatNWB currently treats every empty required property as missing and blocks export with NWB:RequiredPropertyMissing.
This does not match the requiredness semantics clarified in NeurodataWithoutBorders/nwb-schema#692: a required dataset, attribute, group, or link must be present, but its value may be empty when the schema permits an empty value or zero-length shape. Requiredness describes presence, not non-emptiness.
The current check in types.untyped.MetaClass.checkRequiredProps uses isempty(obj.(propertyName)) to determine whether a required property is missing. This conflates two different states:
- the property was not provided; and
- the property was intentionally provided with a valid empty value.
Generated export methods also commonly guard writes with ~isempty(...). For example, types.core.TimeSeries.export does not write data when data is empty. Therefore, relaxing checkRequiredProps alone would allow export to continue but could still omit the required dataset from the file.
Expected behavior
MatNWB should distinguish an unset required property from an explicitly set empty property:
- an unset required property should continue to raise
NWB:RequiredPropertyMissing;
- an explicitly set empty required property should pass required-property validation when the schema permits an empty value; and
- export should create the required HDF5 object with the correct empty value, shape, and dtype.
Proposed fixes
Two coordinated changes are needed:
- Track presence independently of value. Replace the
isempty-based required-property check with a mechanism that can distinguish “unset” from “explicitly set to empty.” Possible implementations include tracking constructor/setter assignment or using an internal unset sentinel. Simply accepting all empty values would remove useful validation for genuinely missing required properties.
- Export explicitly present empty values. Update the generator/export logic so required properties that were explicitly set are written even when empty. Optional unset properties should remain omitted. Empty datasets must preserve the schema-compatible dtype and dimensionality.
The implementation should cover required datasets and attributes first, then verify whether required groups and links need equivalent presence handling.
Tests
Add focused tests confirming that:
- an unset required property still fails export;
- an explicitly set, schema-valid empty required property exports successfully;
- the required HDF5 object exists after export with the expected empty shape and dtype; and
- the file round-trips through
nwbRead without converting the present empty property back into an absent property.
Upstream discussion: NeurodataWithoutBorders/nwb-schema#692
🤖 Generated with Codex
What happened?
MatNWB currently treats every empty required property as missing and blocks export with
NWB:RequiredPropertyMissing.This does not match the requiredness semantics clarified in NeurodataWithoutBorders/nwb-schema#692: a required dataset, attribute, group, or link must be present, but its value may be empty when the schema permits an empty value or zero-length shape. Requiredness describes presence, not non-emptiness.
The current check in
types.untyped.MetaClass.checkRequiredPropsusesisempty(obj.(propertyName))to determine whether a required property is missing. This conflates two different states:Generated export methods also commonly guard writes with
~isempty(...). For example,types.core.TimeSeries.exportdoes not writedatawhendatais empty. Therefore, relaxingcheckRequiredPropsalone would allow export to continue but could still omit the required dataset from the file.Expected behavior
MatNWB should distinguish an unset required property from an explicitly set empty property:
NWB:RequiredPropertyMissing;Proposed fixes
Two coordinated changes are needed:
isempty-based required-property check with a mechanism that can distinguish “unset” from “explicitly set to empty.” Possible implementations include tracking constructor/setter assignment or using an internal unset sentinel. Simply accepting all empty values would remove useful validation for genuinely missing required properties.The implementation should cover required datasets and attributes first, then verify whether required groups and links need equivalent presence handling.
Tests
Add focused tests confirming that:
nwbReadwithout converting the present empty property back into an absent property.Upstream discussion: NeurodataWithoutBorders/nwb-schema#692
🤖 Generated with Codex