Skip to content

Commit fb7b2c3

Browse files
author
Lawrence
committed
Support tables in getRow and addRow tests
With fixes pertaining to getting the tests passing.
1 parent 41b85a2 commit fb7b2c3

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

+tests/+system/DynamicTableTest.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ function addContainer(~, file)
66
'description', 'test dynamic table column',...
77
'colnames', colnames);
88

9+
id = primes(2000) .';
910
for i = 1:100
1011
start_time = i;
1112
stop_time = i + 1;
1213
rand_data = rand(5,1);
13-
id = primes(i);
14-
if isempty(id)
15-
id = 0;
16-
else
17-
id = id(end);
18-
end
1914
file.intervals_trials.addRow(...
2015
'start_time', start_time,...
2116
'stop_time', stop_time,...
2217
'randomvalues', rand_data,...
23-
'id', id,...
18+
'id', id(i),...
2419
'tablepath', '/intervals/trials');
2520
end
21+
t = table(id(101:200), (101:200) .', (102:201) .', mat2cell(rand(500,1), repmat(5, 100, 1)),...
22+
'VariableNames', {'id', 'start_time', 'stop_time', 'randomvalues'});
23+
file.intervals_trials.addRow(t);
2624
end
2725

2826
function c = getContainer(~, file)
@@ -49,8 +47,8 @@ function getRowTest(testCase)
4947
ExpectedTable = testCase.file.intervals_trials;
5048
testCase.verifyEqual(ExpectedTable.getRow(5), ActualTable.getRow(5));
5149
testCase.verifyEqual(ExpectedTable.getRow([5 6]), ActualTable.getRow([5 6]));
52-
testCase.verifyEqual(ExpectedTable.getRow(97, 'useId', true),...
53-
ActualTable.getRow(97, 'useId', true));
50+
testCase.verifyEqual(ExpectedTable.getRow([1153, 1217], 'useId', true),...
51+
ActualTable.getRow([1153, 1217], 'useId', true));
5452
end
5553
end
5654
end

+types/+util/+dynamictable/addRow.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ function addRow(DynamicTable, varargin)
3131
'MatNWB:DynamicTable:AddRow:NoColumns',...
3232
['The `colnames` property of the Dynamic Table needs to be populated with a cell array '...
3333
'of column names before being able to add row data.']);
34-
assert(nargin > 2, 'MatNWB:DynamicTable:AddRow:NoData',...
35-
'Not enough arguments');
34+
assert(nargin > 1, 'MatNWB:DynamicTable:AddRow:NoData', 'Not enough arguments');
3635

3736
if isempty(DynamicTable.id)
3837
DynamicTable.id = types.hdmf_common.ElementIdentifiers();

+types/+util/+dynamictable/addTableRow.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ function addTableRow(DynamicTable, subTable, varargin)
55
addParameter(p, 'tablepath', '', @(x)ischar(x)); % required for ragged arrays.
66
parse(p, varargin{:});
77

8-
rowNames = subTable.VariableNames;
8+
rowNames = subTable.Properties.VariableNames;
99
missingColumns = setdiff(DynamicTable.colnames, rowNames);
1010
assert(isempty(missingColumns),...
1111
'MatNWB:DynamicTable:AddRow:MissingColumns',...
1212
'Missing columns { %s }', strjoin(missingColumns, ', '));
1313

14-
isIdInTable = any(strcmp(subTable.VariableNames, 'id'));
14+
isIdInTable = any(strcmp(rowNames, 'id'));
1515
isIdKeywordArg = ~any(strcmp(p.UsingDefaults, 'id'));
1616
if isIdInTable
1717
idData = subTable.id;
@@ -37,7 +37,7 @@ function addTableRow(DynamicTable, subTable, varargin)
3737
rv = subTable.(rn);
3838

3939
if isKey(TypeMap, rn)
40-
rv = validateType(TypeMap(rn), rv);
40+
validateType(TypeMap(rn), rv);
4141
end
4242

4343
% instantiate vector index here because it's dependent on the table

+types/+util/+dynamictable/addVarargRow.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function addVarargRow(DynamicTable, varargin)
99
addParameter(p, DynamicTable.colnames{i}, []);
1010
end
1111

12+
parse(p, varargin{:});
13+
1214
assert(isempty(fieldnames(p.Unmatched)),...
1315
'MatNWB:DynamicTable:AddRow:InvalidColumns',...
1416
'Invalid column name(s) { %s }', strjoin(fieldnames(p.Unmatched), ', '));

+types/+util/+dynamictable/addVecInd.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
if ~endsWith(tablepath, '/')
1212
tablepath = [tablepath '/'];
1313
end
14-
vecTarget = types.untyped.ObjectView([tablepath rn]);
14+
vecTarget = types.untyped.ObjectView([tablepath colName]);
1515
oldDataHeight = 0;
16-
if isKey(DynamicTable.vectordata, rn) || isprop(DynamicTable, rn)
17-
if isprop(DynamicTable, rn)
18-
VecData = DynamicTable.(rn);
16+
if isKey(DynamicTable.vectordata, colName) || isprop(DynamicTable, colName)
17+
if isprop(DynamicTable, colName)
18+
VecData = DynamicTable.(colName);
1919
else
20-
VecData = DynamicTable.vectordata.get(rn);
20+
VecData = DynamicTable.vectordata.get(colName);
2121
end
2222
if isa(VecData.data, 'types.untyped.DataPipe')
2323
oldDataHeight = VecData.data.offset;

+types/+util/+dynamictable/getIndex.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
%GETINDEX Given a dynamic table and its column name, get its VectorIndex column name
33
validateattributes(DynamicTable, {'types.hdmf_common.DynamicTable'}, {'scalar'});
44
validateattributes(column, {'char'}, {'scalartext'});
5+
indexName = '';
6+
if strcmp(column, 'id')
7+
return;
8+
end
59
assert(any(strcmp(DynamicTable.colnames, column)),...
610
'MatNWB:GetIndex:InvalidColumn',...
711
'Column name not found `%s`', column);
8-
indexName = '';
912

1013
vecIndKeys = keys(DynamicTable.vectorindex);
1114
for i = 1:length(vecIndKeys)

0 commit comments

Comments
 (0)