Skip to content

Commit

Permalink
Fix bug and add test (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad authored Feb 16, 2025
1 parent c8c855d commit a9fad2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions +tests/+unit/dynamicTableTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,36 @@ function testToTableForNdVectorData(testCase)
end
end

function testToTableForTableImportedFromFile(testCase)
fileName = "testToTableForTableImportedFromFile.nwb";

nwb = NwbFile( ...
'session_description', 'test file for nwb export', ...
'identifier', 'export_test', ...
'session_start_time', datetime("now", 'TimeZone', 'local') );

numTableRows = 10;

dynamicTable = types.hdmf_common.DynamicTable( ...
'description', 'test table with n-dimensional VectorData', ...
'colnames', {'columnA', 'columnB'}, ...
'columnA', types.hdmf_common.VectorData(...
'description', 'first_column', ...
'data', randi(10, [1, numTableRows])), ...
'columnB', types.hdmf_common.VectorData(...
'description', 'second_column', ...
'data', randi(10, [1, numTableRows])), ...
'id', types.hdmf_common.ElementIdentifiers('data', (0:numTableRows-1)' ) );

nwb.acquisition.set('DynamicTable', dynamicTable);
nwbExport(nwb, fileName)

nwbIn = nwbRead(fileName);

T = nwbIn.acquisition.get('DynamicTable').toTable();
testCase.verifyClass(T, 'table')
end


% Non-test functions
function dtr_table = createDynamicTableWithTableRegionReferences()
Expand Down
3 changes: 2 additions & 1 deletion +types/+util/+dynamictable/nwbToTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
'columns', remainingColumns ...
)];

% Update the columns order to be the same as the original
% Update the columns order to be the same as the original
if iscolumn(columns); columns = transpose(columns); end
matlabTable = matlabTable(:, [{'id'}, columns]);

% Add variable descriptions
Expand Down

0 comments on commit a9fad2d

Please sign in to comment.