Skip to content

Commit 5001f15

Browse files
mgxdeffigies
authored andcommitted
fix: allow none / optional to be overriden
1 parent 37a8147 commit 5001f15

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
@@ -238,6 +238,14 @@ def collect_data(
238238
...
239239
ValueError: Conflicting entities for "session" found: madeup // retest
240240
241+
>>> bids_root, _ = collect_data(
242+
... str(datadir / 'ds114'),
243+
... '01',
244+
... bids_validate=False,
245+
... session_id=None,
246+
... bids_filters={'t1w': {'session': 'retest'}})
247+
>>> bids_root['t1w'] # doctest: +ELLIPSIS
248+
['.../ds114/sub-01/ses-retest/anat/sub-01_ses-retest_T1w.nii.gz']
241249
"""
242250
if isinstance(bids_dir, BIDSLayout):
243251
layout = bids_dir
@@ -247,11 +255,12 @@ def collect_data(
247255
if not queries:
248256
queries = copy.deepcopy(DEFAULT_BIDS_QUERIES)
249257

258+
session_id = session_id or Query.OPTIONAL
250259
layout_get_kwargs = {
251260
'return_type': 'file',
252261
'subject': participant_label,
253262
'extension': ['.nii', '.nii.gz'],
254-
'session': session_id or Query.OPTIONAL,
263+
'session': session_id,
255264
}
256265

257266
reserved_entities = [('subject', participant_label), ('session', session_id)]
@@ -260,6 +269,8 @@ def collect_data(
260269
for acq, entities in bids_filters.items():
261270
# BIDS filters will not be able to override subject / session entities
262271
for entity, param in reserved_entities:
272+
if param == Query.OPTIONAL:
273+
continue
263274
if entity in entities and listify(param) != listify(entities[entity]):
264275
raise ValueError(
265276
f'Conflicting entities for "{entity}" found: {entities[entity]} // {param}'

0 commit comments

Comments
 (0)