@@ -238,6 +238,14 @@ def collect_data(
238
238
...
239
239
ValueError: Conflicting entities for "session" found: madeup // retest
240
240
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']
241
249
"""
242
250
if isinstance (bids_dir , BIDSLayout ):
243
251
layout = bids_dir
@@ -247,11 +255,12 @@ def collect_data(
247
255
if not queries :
248
256
queries = copy .deepcopy (DEFAULT_BIDS_QUERIES )
249
257
258
+ session_id = session_id or Query .OPTIONAL
250
259
layout_get_kwargs = {
251
260
'return_type' : 'file' ,
252
261
'subject' : participant_label ,
253
262
'extension' : ['.nii' , '.nii.gz' ],
254
- 'session' : session_id or Query . OPTIONAL ,
263
+ 'session' : session_id ,
255
264
}
256
265
257
266
reserved_entities = [('subject' , participant_label ), ('session' , session_id )]
@@ -260,6 +269,8 @@ def collect_data(
260
269
for acq , entities in bids_filters .items ():
261
270
# BIDS filters will not be able to override subject / session entities
262
271
for entity , param in reserved_entities :
272
+ if param == Query .OPTIONAL :
273
+ continue
263
274
if entity in entities and listify (param ) != listify (entities [entity ]):
264
275
raise ValueError (
265
276
f'Conflicting entities for "{ entity } " found: { entities [entity ]} // { param } '
0 commit comments