Check DynamicTable columns against __columns__ - #1557
Open
adityasingh2400 wants to merge 3 commits into
Open
Conversation
DynamicTable.__init__ did not check the columns passed via 'columns' against __columns__, so a column whose name matched a predefined column could be passed with the wrong class and was silently accepted. This resolves the TODO at the top of the columns processing block. add_column had the same root cause from the other direction: col_cls was defaulted to VectorData before the predefined spec was consulted, so a caller who never passed col_cls got a plain VectorData for a predefined typed column plus a warning that blamed an argument they did not supply. The predefined class is now used when the caller does not pass col_cls, and the warning is emitted only for a col_cls that actually conflicts. Fix hdmf-dev#1553
4 tasks
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
Fix #1553
DynamicTable.__init__did not check the columns passed viacolumns=against__columns__, so a column whose name matched a predefined column could be passed in with the wrong class and was silently accepted. This resolves the long-standing TODO at the top of the columns processing block. In PyNWB this is how anEventsTableends up with a plainVectorDatanamedtimestampwhere the schema requires aTimestampVectorData, producing a file that fails NWB validation.add_columnhad the same root cause from the other direction.col_clswas defaulted toVectorDatabefore the predefined spec was consulted, so a caller who never passedcol_clsgot a plainVectorDatafor a predefined typed column, plus a warning that blamed an argument they did not supply.The fix
The constructor now checks each passed column against
__columns__and warns on a class mismatch. This follows the "warn now, error in a future version of HDMF" wording thatadd_columnalready uses, so the two paths report the same class of problem the same way. The required class comes from the spec'sclasskey, falling back toDynamicTableRegionfortable: TrueandEnumDataforenum: True, which covers the table region case named in the original TODO. The check isisinstance, so a subclass of the required class satisfies the spec, matching how a subtype satisfiesdata_type_inc.add_columnnow consults the predefined spec before falling back toVectorData. A caller who does not passcol_clsgets the class the spec asks for, and the mismatch warning fires only when acol_clsthat actually conflicts was passed. An explicittable=orenum=argument still wins, as before.One existing test,
test_add_opt_column_mismatched_col_cls, asserted the old behavior of the second case: it calledadd_column(name='col10', ...)with nocol_clsand expected both the misleading warning and a plainVectorData, even thoughcol10is predefined withclass=EnumData. That test now passes an actually-conflictingcol_cls=VectorData, which is what its name describes, and the no-col_clscase is covered by a newtest_add_opt_column_uses_spec_col_cls.How to test the behavior?
Five tests were added or updated in
TestDynamicTableClassColumns. With the source change reverted and the tests kept, three fail:With the fix applied all 34 tests in that class pass, and the full suite matches the baseline:
1869 passed, 118 skipped, 1 xfailed, 919 subtests passed.Checklist
CHANGELOG.mdwith your changes?