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

update to checkConfig utility function to remove null characters from column names of DynamicTable #366

Merged
merged 4 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions +tests/+system/DynamicTableTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
methods
function addContainer(~, file)
colnames = {'start_time', 'stop_time', 'randomvalues', 'random_multi', 'stringdata'};
%add trailing nulls to columnames
for c =1:length(colnames)
colnames{c} = char([double(colnames{c}) zeros(1,randi(10))]);
end
file.intervals_trials = types.core.TimeIntervals(...
'description', 'test dynamic table column',...
'colnames', colnames);
Expand Down
15 changes: 15 additions & 0 deletions +types/+util/+dynamictable/checkConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ function checkConfig(DynamicTable, varargin)
else
ignoreList = varargin{1};
end
% remove null characters from column names
if ~isempty(DynamicTable.colnames)
if iscell(DynamicTable.colnames)
DynamicTable.colnames = cellfun(...
@removeNulls, DynamicTable.colnames, ...
'UniformOutput',false ...
);
else
DynamicTable.colnames = removeNulls(DynamicTable.colnames);
end
end
% do not check specified columns - useful for classes that build on DynamicTable class
columns = setdiff(DynamicTable.colnames,ignoreList);
% keep track of last non-ragged column index; to prevent looping over array twice
Expand Down Expand Up @@ -93,4 +104,8 @@ function checkConfig(DynamicTable, varargin)
else % legacy Element Identifiers
DynamicTable.id = types.core.ElementIdentifiers();
end
end
end
function in = removeNulls(in)
in(double(in) == 0) = [];
end