Skip to content

Add AlignedDynamicTable non-generated base class with category table validation#837

Draft
ehennestad wants to merge 27 commits into
codex/report-schema-violation-contextfrom
codex/aligned-dynamic-table-add-category
Draft

Add AlignedDynamicTable non-generated base class with category table validation#837
ehennestad wants to merge 27 commits into
codex/report-schema-violation-contextfrom
codex/aligned-dynamic-table-add-category

Conversation

@ehennestad

@ehennestad ehennestad commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Depends on #836 — merge that first

Motivation

The AlignedDynamicTable schema defines two requirements in docstrings that cannot be enforced by the generated class alone:

  1. All sub-tables added to an AlignedDynamicTable "MUST have the same number of rows" (source).
  2. The names in the categories property MUST match the names of category tables in the AlignedDynamicTable (source).

Without additional runtime validation, users can create invalid NWB files when using AlignedDynamicTable or its subtypes.

This PR adds validation hooks for AlignedDynamicTable through a custom base class. It also adds convenience APIs so valid tables are easier to construct: schema-defined category tables auto-register in categories when assigned, and custom category tables can be added with addCategory(name, table).

This PR stacks on #836 and uses its schema validation reporting context to maintain backwards-compatibility by making AlignedDynamicTable validation on construction warn instead of error to ensure pre-PR icephys tutorial examples can still run without breaking.

Example usage (updated snippets from icephys tutorial)

1. categories do not need to be listed when the table is initialized with rows — assigning a category table later registers it automatically:

% before
ic_rec_table = types.core.IntracellularRecordingsTable( ...
    'categories', {'electrodes', 'stimuli', 'responses'}, ...  % name is manually added to categories
    'colnames', {'recordings_tag'}, ...
    'id', types.hdmf_common.ElementIdentifiers('data', int64([0; 1; 2])), ...
    'recordings_tag', ...);
ic_rec_table.electrodes = ...;   % table is assigned afterwards

% after
ic_rec_table = types.core.IntracellularRecordingsTable( ...
    'colnames', {'recordings_tag'}, ...
    'id', types.hdmf_common.ElementIdentifiers('data', int64([0; 1; 2])), ...
    'recordings_tag', ...);
ic_rec_table.electrodes = ...;   % auto-registers in name `categories`

2. Use addCategory for custom categories instead of the manual two-step:

% before
ic_rec_table.categories = [ic_rec_table.categories, {'recording_lab_data'}];
ic_rec_table.dynamictable.set('recording_lab_data', customTable);

% after
ic_rec_table.addCategory("recording_lab_data", customTable);

How to test the behavior?

runtests('+tests/+system/AlignedDynamicTableTest.m')

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

🤖 Generated with Codex

commit 89aaadded34998b5256f3d27b2d6ba73a860a042
Author: ehennestad <ehennestad@gmail.com>
Date:   Mon Jun 22 14:41:36 2026 +0200

    Update AlignedDynamicTableBase.m

    one line validation

commit a756a89f9be70116f32d1c9a23fa44744ff73485
Author: ehennestad <ehennestad@gmail.com>
Date:   Mon Jun 22 14:39:20 2026 +0200

    refactor: clarify aligned dynamic table helpers

commit a5d5dc30493a5745c069b4b6dcb2fd9bd9cf0397
Author: ehennestad <ehennestad@gmail.com>
Date:   Mon Jun 22 13:28:48 2026 +0200

    refactor: clarify aligned table consistency validation

commit b5bb8313d0bab73236da507dfe405fdd277124db
Author: ehennestad <ehennestad@gmail.com>
Date:   Mon Jun 22 13:24:21 2026 +0200

    refactor: extract aligned table height establishment

commit 6716530829ed69e5571624c6fe37fd9236c1394c
Author: ehennestad <ehennestad@gmail.com>
Date:   Mon Jun 22 13:03:43 2026 +0200

    refactor: rename aligned table consistency validation

commit a9bda90e128ec29bd6401e7aac46b7aeecf1cd9c
Author: ehennestad <ehennestad@gmail.com>
Date:   Mon Jun 22 12:49:36 2026 +0200

    feat: add aligned dynamic table base
LLM assisted docstring tightening
Add test exercising validateUniqueCategoryNames
Add tests for improved coverage
Add test checking that empty datapipe ids are filled if table has/gets established height
Ensure backwards compatibility for pre-PR icephys tutorial syntax showing how to create an IntraCellularRecordings table
@ehennestad ehennestad mentioned this pull request Jun 26, 2026
5 tasks
@ehennestad ehennestad changed the title Add AlignedDynamicTable category utilities Add AlignedDynamicTable non-generated base class with category table validation Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant