matnwb
matnwb copied to clipboard
[Bug]: toTable method does not work if a DynamicTableRegion is added as a last column of a table
What happened?
If a DynamicTableRegion is added as a last column to a dynamic table, the toColumn method with the second argument (index flag) set to false does not work.
Steps to Reproduce
T = table([1;2;3], {'a';'b';'c'}, 'VariableNames', {'col1', 'col2'});
T.Properties.VariableDescriptions = {'column #1', 'column #2'};
T = util.table2nwb(T);
dtr_col = types.hdmf_common.DynamicTableRegion( ...
'description', 'references multiple rows of earlier table', ...
'data', [0; 1; 1; 0], ... # 0-indexed
'table',types.untyped.ObjectView(T) ... % object view of target table
);
data_col = types.hdmf_common.VectorData( ...
'description', 'data column', ...
'data', {'a'; 'b'; 'c'; 'd'} ...
);
dtr_table = types.hdmf_common.DynamicTable( ...
'description', 'test table with DynamicTableRegion', ...
'colnames', {'dtr_col', 'data_col'}, ...
'dtr_col', dtr_col, ...
'data_col',data_col, ...
'id',types.hdmf_common.ElementIdentifiers('data', [0; 1; 2; 3]) ...
);
dtr_table.toTable() % Works
ans =
4×3 table
id dtr_col data_col
__ _______ ________
0 0 {'a'}
1 1 {'b'}
2 1 {'c'}
3 0 {'d'}
dtr_table.toTable(false) % Works
ans =
4×3 table
id dtr_col data_col
__ ___________ ________
0 {1×2 table} {'a'}
1 {1×2 table} {'b'}
2 {1×2 table} {'c'}
3 {1×2 table} {'d'}
% If instead the dtr_col is added as the last column of the table:
dtr_table = types.hdmf_common.DynamicTable( ...
'description', 'test table with DynamicTableRegion', ...
'colnames', {'data_col', 'dtr_col'}, ... % Columns changed places
'dtr_col', dtr_col, ...
'data_col',data_col, ...
'id',types.hdmf_common.ElementIdentifiers('data', [0; 1; 2; 3]) ...
);
dtr_table.toTable() % Works
ans =
4×3 table
id data_col dtr_col
__ ________ _______
0 {'a'} 0
1 {'b'} 1
2 {'c'} 1
3 {'d'} 0
dtr_table.toTable(false) % Does not work
ans =
4×3 table
id data_col dtr_col
__ ________ _______
0 {'a'} 0
1 {'b'} 1
2 {'c'} 1
3 {'d'} 0
Error Message
No error, but the last column in the last example should contain table elements
Operating System
macOS
Matlab Version
R2023b
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
- [X] Have you ensured this bug was not already reported?