Skip to content

Commit 92a65a3

Browse files
authored
Merge pull request #509 from NeurodataWithoutBorders/508-remove-international-datestring-parsing
Remove international datestring parsing for version checks
2 parents 43cdffb + af0db0a commit 92a65a3

File tree

2 files changed

+99
-99
lines changed

2 files changed

+99
-99
lines changed

+io/parseDataset.m

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
11
function parsed = parseDataset(filename, info, fullpath, Blacklist)
2-
%typed and untyped being container maps containing type and untyped datasets
3-
% the maps store information regarding information and stored data
4-
% NOTE, dataset name is in path format so we need to parse that out.
5-
name = info.Name;
2+
%typed and untyped being container maps containing type and untyped datasets
3+
% the maps store information regarding information and stored data
4+
% NOTE, dataset name is in path format so we need to parse that out.
5+
name = info.Name;
66

7-
%check if typed and parse attributes
8-
[attrargs, Type] = io.parseAttributes(filename, info.Attributes, fullpath, Blacklist);
7+
%check if typed and parse attributes
8+
[attrargs, Type] = io.parseAttributes(filename, info.Attributes, fullpath, Blacklist);
99

10-
fid = H5F.open(filename, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');
11-
did = H5D.open(fid, fullpath);
12-
props = attrargs;
13-
datatype = info.Datatype;
14-
dataspace = info.Dataspace;
10+
fid = H5F.open(filename, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');
11+
did = H5D.open(fid, fullpath);
12+
props = attrargs;
13+
datatype = info.Datatype;
14+
dataspace = info.Dataspace;
1515

16-
parsed = containers.Map;
17-
afields = keys(attrargs);
18-
if ~isempty(afields)
19-
anames = strcat(name, '_', afields);
20-
parsed = [parsed; containers.Map(anames, attrargs.values(afields))];
21-
end
16+
parsed = containers.Map;
17+
afields = keys(attrargs);
18+
if ~isempty(afields)
19+
anames = strcat(name, '_', afields);
20+
parsed = [parsed; containers.Map(anames, attrargs.values(afields))];
21+
end
2222

23-
% loading h5t references are required
24-
% unfortunately also a bottleneck
25-
if strcmp(datatype.Class, 'H5T_REFERENCE')
26-
tid = H5D.get_type(did);
27-
data = io.parseReference(did, tid, H5D.read(did));
28-
H5T.close(tid);
29-
elseif ~strcmp(dataspace.Type, 'simple')
30-
data = H5D.read(did);
23+
% loading h5t references are required
24+
% unfortunately also a bottleneck
25+
if strcmp(datatype.Class, 'H5T_REFERENCE')
26+
tid = H5D.get_type(did);
27+
data = io.parseReference(did, tid, H5D.read(did));
28+
H5T.close(tid);
29+
elseif ~strcmp(dataspace.Type, 'simple')
30+
data = H5D.read(did);
3131

32-
switch datatype.Class
33-
case 'H5T_STRING'
34-
if datetime(version('-date')) < datetime('25-Feb-2020')
35-
% MATLAB 2020a fixed string support for HDF5, making
36-
% reading strings "consistent" with regular use.
37-
data = data .';
38-
end
39-
datadim = size(data);
40-
if datadim(1) > 1
41-
%multidimensional strings should become cellstr
42-
data = strtrim(mat2cell(data, ones(datadim(1), 1), datadim(2)));
43-
end
44-
case 'H5T_ENUM'
45-
if io.isBool(datatype.Type)
46-
data = strcmp('TRUE', data);
47-
else
48-
warning('NWB:Dataset:UnknownEnum', ...
49-
['Encountered unknown enum under field `%s` with %d members. ' ...
50-
'Will be saved as cell array of characters.'], ...
51-
info.Name, length(datatype.Type.Member));
52-
end
53-
end
54-
else
55-
sid = H5D.get_space(did);
56-
pid = H5D.get_create_plist(did);
57-
isChunked = H5P.get_layout(pid) == H5ML.get_constant_value('H5D_CHUNKED');
58-
59-
tid = H5D.get_type(did);
60-
class_id = H5T.get_class(tid);
61-
isNumeric = class_id == H5ML.get_constant_value('H5T_INTEGER')...
62-
|| class_id == H5ML.get_constant_value('H5T_FLOAT');
63-
if isChunked && isNumeric
64-
data = types.untyped.DataPipe('filename', filename, 'path', fullpath);
65-
elseif any(dataspace.Size == 0)
66-
data = [];
32+
switch datatype.Class
33+
case 'H5T_STRING'
34+
if verLessThan('MATLAB', '9.8')
35+
% MATLAB 2020a fixed string support for HDF5, making
36+
% reading strings "consistent" with regular use.
37+
data = data .';
38+
end
39+
datadim = size(data);
40+
if datadim(1) > 1
41+
%multidimensional strings should become cellstr
42+
data = strtrim(mat2cell(data, ones(datadim(1), 1), datadim(2)));
43+
end
44+
case 'H5T_ENUM'
45+
if io.isBool(datatype.Type)
46+
data = strcmp('TRUE', data);
47+
else
48+
warning('NWB:Dataset:UnknownEnum', ...
49+
['Encountered unknown enum under field `%s` with %d members. ' ...
50+
'Will be saved as cell array of characters.'], ...
51+
info.Name, length(datatype.Type.Member));
52+
end
53+
end
6754
else
68-
data = types.untyped.DataStub(filename, fullpath);
55+
sid = H5D.get_space(did);
56+
pid = H5D.get_create_plist(did);
57+
isChunked = H5P.get_layout(pid) == H5ML.get_constant_value('H5D_CHUNKED');
58+
59+
tid = H5D.get_type(did);
60+
class_id = H5T.get_class(tid);
61+
isNumeric = class_id == H5ML.get_constant_value('H5T_INTEGER')...
62+
|| class_id == H5ML.get_constant_value('H5T_FLOAT');
63+
if isChunked && isNumeric
64+
data = types.untyped.DataPipe('filename', filename, 'path', fullpath);
65+
elseif any(dataspace.Size == 0)
66+
data = [];
67+
else
68+
data = types.untyped.DataStub(filename, fullpath);
69+
end
70+
H5T.close(tid);
71+
H5P.close(pid);
72+
H5S.close(sid);
6973
end
70-
H5T.close(tid);
71-
H5P.close(pid);
72-
H5S.close(sid);
73-
end
7474

75-
if isempty(Type.typename)
76-
%untyped group
77-
parsed(name) = data;
78-
else
79-
props('data') = data;
80-
kwargs = io.map2kwargs(props);
81-
parsed = eval([Type.typename '(kwargs{:})']);
82-
end
83-
H5D.close(did);
84-
H5F.close(fid);
75+
if isempty(Type.typename)
76+
%untyped group
77+
parsed(name) = data;
78+
else
79+
props('data') = data;
80+
kwargs = io.map2kwargs(props);
81+
parsed = eval([Type.typename '(kwargs{:})']);
82+
end
83+
H5D.close(did);
84+
H5F.close(fid);
8585
end

+tests/+unit/boolTest.m

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
function tests = boolTest()
2-
tests = functiontests(localfunctions);
2+
tests = functiontests(localfunctions);
33
end
44

55
function setupOnce(testCase)
6-
rootPath = fullfile(fileparts(mfilename('fullpath')), '..', '..');
7-
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(rootPath));
6+
rootPath = fullfile(fileparts(mfilename('fullpath')), '..', '..');
7+
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(rootPath));
88
end
99

1010
function setup(testCase)
11-
testCase.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture);
12-
generateCore('savedir', '.');
13-
schemaPath = fullfile(misc.getMatnwbDir(),...
14-
'+tests', '+unit', 'boolSchema', 'bool.namespace.yaml');
15-
generateExtension(schemaPath, 'savedir', '.');
16-
rehash();
11+
testCase.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture);
12+
generateCore('savedir', '.');
13+
schemaPath = fullfile(misc.getMatnwbDir(),...
14+
'+tests', '+unit', 'boolSchema', 'bool.namespace.yaml');
15+
generateExtension(schemaPath, 'savedir', '.');
16+
rehash();
1717
end
1818

1919
function testIo(testCase)
20-
nwb = NwbFile(...
21-
'identifier', 'BOOL',...
22-
'session_description', 'test bool',...
23-
'session_start_time', datetime());
24-
boolContainer = types.bool.BoolContainer(...
25-
'data', logical(randi([0,1], 100, 1)), ...
26-
'attribute', false);
27-
scalarBoolContainer = types.bool.BoolContainer(...
28-
'data', false, ...
29-
'attribute', true);
30-
nwb.acquisition.set('bool', boolContainer);
31-
nwb.acquisition.set('scalarbool', scalarBoolContainer);
32-
nwb.export('test.nwb');
33-
nwbActual = nwbRead('test.nwb', 'ignorecache');
34-
tests.util.verifyContainerEqual(testCase, nwbActual, nwb);
20+
nwb = NwbFile(...
21+
'identifier', 'BOOL',...
22+
'session_description', 'test bool',...
23+
'session_start_time', datetime());
24+
boolContainer = types.bool.BoolContainer(...
25+
'data', logical(randi([0,1], 100, 1)), ...
26+
'attribute', false);
27+
scalarBoolContainer = types.bool.BoolContainer(...
28+
'data', false, ...
29+
'attribute', true);
30+
nwb.acquisition.set('bool', boolContainer);
31+
nwb.acquisition.set('scalarbool', scalarBoolContainer);
32+
nwb.export('test.nwb');
33+
nwbActual = nwbRead('test.nwb', 'ignorecache');
34+
tests.util.verifyContainerEqual(testCase, nwbActual, nwb);
3535
end

0 commit comments

Comments
 (0)