Skip to content

fix(dynamictable): accept string descriptions in toTable - #947

Draft
ehennestad wants to merge 1 commit into
mainfrom
fix-to-table-string-descriptions
Draft

ehennestad wants to merge 1 commit into
mainfrom
fix-to-table-string-descriptions

Conversation

@ehennestad

Copy link
Copy Markdown
Contributor

Motivation

Makes toTable work on a DynamicTable whose column description, or category description for an AlignedDynamicTable, is a string scalar. It failed with an error about VariableDescriptions.

Problem — A user creates a column with a double-quoted description, such as types.hdmf_common.VectorData('description', "whether the trial was correct", ...). The table is created and exported without complaint, because the description property accepts a string scalar and keeps it as one. toTable then fails with The VariableDescriptions property must be a string array or a cell array of character vectors. The cause is that toTable collects the descriptions in a cell array that starts with '' for the id column, so a string description makes the cell array hold both character vectors and strings, which a MATLAB table does not accept as VariableDescriptions.

Solution — The descriptions are converted to character vectors when they are collected, so toTable returns the table and its VariableDescriptions hold the text of each description.

What changed

  • toTable accepts string scalar descriptions of columns and of the categories of an AlignedDynamicTable.
  • types.util.dynamictable.internal.getColumnDescriptions returns a cell array of character vectors for any description class the description property accepts.

Example

dynamicTable = types.hdmf_common.DynamicTable( ...
    'description', 'trials', ...
    'colnames', {'correct'}, ...
    'correct', types.hdmf_common.VectorData( ...
        'description', "whether the trial was correct", ...
        'data', [true; false; true]), ...
    'id', types.hdmf_common.ElementIdentifiers('data', int64((0:2)')));
matlabTable = dynamicTable.toTable();
disp(matlabTable.Properties.VariableDescriptions)

Before — toTable stops while assigning the variable descriptions.

Error: The VariableDescriptions property must be a string array or a cell array of character vectors.

After — The table is returned. The first description belongs to the id column, which has none.

    {0×0 char}    {'whether the trial was correct'}

How to test the behavior?

nwbtest('Name', 'tests.unit.dynamicTableTest*')
nwbtest('Name', 'tests.system.AlignedDynamicTableTest*')

testToTableWithStringDescription and testToTableWithStringCategoryDescription fail on main with MATLAB:table:InvalidVarDescr.

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 Claude Code

toTable copies the description of each column, and of each category of
an AlignedDynamicTable, into the VariableDescriptions property of the
MATLAB table. That property takes a cell array of character vectors.
A description may be held as a string scalar, because the description
property accepts one, and the cell array then mixed strings with
character vectors and the assignment failed with
MATLAB:table:InvalidVarDescr.

getColumnDescriptions and nwbToTable now convert each description to
a character vector.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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