Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: toTable method does not work if a DynamicTableRegion is added as a last column of a table #597

Open
2 tasks done
ehennestad opened this issue Sep 17, 2024 · 0 comments · May be fixed by #598
Open
2 tasks done

Comments

@ehennestad
Copy link
Collaborator

ehennestad commented Sep 17, 2024

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

ehennestad added a commit that referenced this issue Sep 17, 2024
@ehennestad ehennestad linked a pull request Sep 17, 2024 that will close this issue
3 tasks
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 a pull request may close this issue.

1 participant