Skip to content

Commit 782d5f0

Browse files
authored
Merge pull request #956 from nipreps/fix/bids-collect-session-id
FIX: Loosen session error on mismatch
2 parents a9fa98a + 8579918 commit 782d5f0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

niworkflows/utils/bids.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ def collect_data(
242242
...
243243
ValueError: Conflicting entities for "session" found: madeup // retest
244244
245+
>>> bids_root, _ = collect_data(
246+
... str(datadir / 'ds114'),
247+
... '01',
248+
... bids_validate=False,
249+
... session_id=None,
250+
... bids_filters={'t1w': {'session': 'retest'}})
251+
>>> bids_root['t1w'] # doctest: +ELLIPSIS
252+
['.../ds114/sub-01/ses-retest/anat/sub-01_ses-retest_T1w.nii.gz']
245253
"""
246254
if isinstance(bids_dir, BIDSLayout):
247255
layout = bids_dir
@@ -251,11 +259,12 @@ def collect_data(
251259
if not queries:
252260
queries = copy.deepcopy(DEFAULT_BIDS_QUERIES)
253261

262+
session_id = session_id or Query.OPTIONAL
254263
layout_get_kwargs = {
255264
'return_type': 'file',
256265
'subject': participant_label,
257266
'extension': ['.nii', '.nii.gz'],
258-
'session': session_id or Query.OPTIONAL,
267+
'session': session_id,
259268
}
260269

261270
reserved_entities = [('subject', participant_label), ('session', session_id)]
@@ -264,6 +273,8 @@ def collect_data(
264273
for acq, entities in bids_filters.items():
265274
# BIDS filters will not be able to override subject / session entities
266275
for entity, param in reserved_entities:
276+
if param == Query.OPTIONAL:
277+
continue
267278
if entity in entities and listify(param) != listify(entities[entity]):
268279
raise ValueError(
269280
f'Conflicting entities for "{entity}" found: {entities[entity]} // {param}'

0 commit comments

Comments
 (0)