Skip to content

Commit

Permalink
[MAINT] Update from main (#606)
Browse files Browse the repository at this point in the history
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

* CI: Use PAT to submit pull requests (#534)

This will ensure that actions run on the PR. The default `GITHUB_TOKEN` is not enabled to do that to avoid a possible loop of new PRs with actions.

* Bump peter-evans/create-pull-request from 4 to 5 (#536)

Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 4 to 5.
- [Release notes](https://github.com/peter-evans/create-pull-request/releases)
- [Commits](peter-evans/create-pull-request@v4...v5)

---
updated-dependencies:
- dependency-name: peter-evans/create-pull-request
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [MAINT] update schema (#548)

* update schema

* readd token$

* update ci (#558)

* [FIX] remove byte order mark from tsv file (#556)

* fix bom

* add data

* octave fix

* Bump matlab-actions/run-command from 1.1.3 to 1.2.0 (#570)

Bumps [matlab-actions/run-command](https://github.com/matlab-actions/run-command) from 1.1.3 to 1.2.0.
- [Release notes](https://github.com/matlab-actions/run-command/releases)
- [Commits](matlab-actions/run-command@v1.1.3...v1.2.0)

---
updated-dependencies:
- dependency-name: matlab-actions/run-command
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [MAINT] update schema (#577)

* update schema

* rm token

* docs: add coxroy as a contributor for bug, ideas, and userTesting (#585)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* BIDS schema update (#587)

Co-authored-by: Remi-Gau <[email protected]>

* BIDS schema update (#592)

Co-authored-by: Remi-Gau <[email protected]>

* BIDS schema update (#594)

Co-authored-by: Remi-Gau <[email protected]>

* Bump matlab-actions/run-command from 1.2.0 to 1.2.1 (#602)

Bumps [matlab-actions/run-command](https://github.com/matlab-actions/run-command) from 1.2.0 to 1.2.1.
- [Release notes](https://github.com/matlab-actions/run-command/releases)
- [Commits](matlab-actions/run-command@v1.2.0...v1.2.1)

---
updated-dependencies:
- dependency-name: matlab-actions/run-command
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [FIX] handle nan and and datetimes when printing tables (#605)

* fix bugs in tables and datetimes

* skip on windows

* update schema

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Chris Markiewicz <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Remi-Gau <[email protected]>
  • Loading branch information
6 people authored Jul 31, 2023
1 parent 3dbfed5 commit d2b1c9c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
22 changes: 16 additions & 6 deletions +bids/+util/tsvwrite.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ function tsvwrite(filename, var)
%
% Based on spm_save.m from SPM12.
%
%

% (C) Copyright 2018 Guillaume Flandin, Wellcome Centre for Human Neuroimaging
%

% (C) Copyright 2018 BIDS-MATLAB developers

delim = sprintf('\t');
Expand Down Expand Up @@ -57,6 +54,7 @@ function tsvwrite(filename, var)
var = num2cell(var);
end

var = convert_datetimes(var);
var = cellfun(@(x) num2str(x, 16), var, 'UniformOutput', false);
var = strtrim(var);
var(cellfun(@(x) strcmp(x, 'NaN'), var)) = {'n/a'};
Expand All @@ -66,9 +64,10 @@ function tsvwrite(filename, var)
write_to_file(filename, var, delim);

elseif isa(var, 'table')
writetable(var, filename, ...
'FileType', 'text', ...
'Delimiter', delim);
header = var.Properties.VariableNames;
var = table2cell(var);
var = cat(1, header, var);
bids.util.tsvwrite(filename, var);

else
error('Unknown data type.');
Expand All @@ -77,6 +76,17 @@ function tsvwrite(filename, var)

end

function var = convert_datetimes(var)
if bids.internal.is_octave
return
end
is_datetime = find(cellfun(@(x) isdatetime(x), var(:)));
for i = 1:numel(is_datetime)
idx = is_datetime(i);
var{idx} = char(var{idx}, 'yyyy-MM-dd''T''HH:mm:ss.SSS'); % bids-compliant datetime
end
end

function write_to_file(filename, var, delim)

fid = fopen(filename, 'Wt');
Expand Down
14 changes: 13 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@
"contributions": [
"bug"
]
},
{
"login": "coxroy",
"name": "coxroy",
"avatar_url": "https://avatars.githubusercontent.com/u/26691793?v=4",
"profile": "https://github.com/coxroy",
"contributions": [
"bug",
"ideas",
"userTesting"
]
}
],
"contributorsPerLine": 7,
Expand All @@ -244,5 +255,6 @@
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true,
"commitConvention": "angular"
"commitConvention": "angular",
"commitType": "docs"
}
2 changes: 2 additions & 0 deletions .github/workflows/run_tests_matlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ jobs:
version: [R2021a, R2021b, R2022a, R2022b]
os: [ubuntu-latest, macos-latest, windows-latest]


runs-on: ${{matrix.os}}

steps:

- name: Install MATLAB
uses: matlab-actions/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Thanks goes to these wonderful people
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/avanaudenhaege"><img src="https://avatars.githubusercontent.com/u/75271651?v=4?s=100" width="100px;" alt="avanaudenhaege"/><br /><sub><b>avanaudenhaege</b></sub></a><br /><a href="https://github.com/bids-standard/bids-matlab/issues?q=author%3Aavanaudenhaege" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/coxroy"><img src="https://avatars.githubusercontent.com/u/26691793?v=4?s=100" width="100px;" alt="coxroy"/><br /><sub><b>coxroy</b></sub></a><br /><a href="https://github.com/bids-standard/bids-matlab/issues?q=author%3Acoxroy" title="Bug reports">🐛</a> <a href="#ideas-coxroy" title="Ideas, Planning, & Feedback">🤔</a> <a href="#userTesting-coxroy" title="User Testing">📓</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion schema.json

Large diffs are not rendered by default.

37 changes: 36 additions & 1 deletion tests/tests_utils/test_tsvwrite.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@
initTestSuite;
end

function test_datetime_in_table()
% TODO fix line issue on windows
if bids.internal.is_octave() || ispc()
moxunit_throw_test_skipped_exception('no datetime in Octave and line issue in windows');
end
x = '201401010000';
acq_time = datetime(x, 'InputFormat', 'yyyyMMddHHmm');
sub_id = {'foo'};
patients = table(sub_id, acq_time);
file = fullfile(tempname(), 'foo.tsv');
bids.util.mkdir(fileparts(file));
bids.util.tsvwrite(file, patients);

FID = fopen(file, 'r');
C = textscan(FID, '%s%s', 'Delimiter', '\t', 'EndOfLine', '\n');
assertEqual(C{2}{2}, '2014-01-01T00:00:00.000');
end

function test_nan_in_table()
% TODO fix line issue on windows
if bids.internal.is_octave() || ispc()
moxunit_throw_test_skipped_exception('no table in Octave and line issue in windows');
end
sub_id = {'foo'; 'bar'};
age = [25; nan];
patients = table(sub_id, age);
file = fullfile(tempname(), 'foo.tsv');
bids.util.mkdir(fileparts(file));
bids.util.tsvwrite(file, patients);

FID = fopen(file, 'r');
C = textscan(FID, '%s%s', 'Delimiter', '\t', 'EndOfLine', '\n');
assertEqual(C{2}{3}, 'n/a');
end

function test_tsvwrite_basic()

pth = fileparts(mfilename('fullpath'));
Expand Down Expand Up @@ -67,7 +102,7 @@ function test_tsvwrite_basic()

FID = fopen(tsv_file, 'r');
C = textscan(FID, '%s%s', 'Delimiter', '\t', 'EndOfLine', '\n');
assertEqual(C{1}{2}, 'n/a'); %
assertEqual(C{1}{2}, 'n/a');

delete(tsv_file);

Expand Down

0 comments on commit d2b1c9c

Please sign in to comment.