Skip to content

Commit 33fa78f

Browse files
authored
fix: processing groups serialization (#3522)
fixes the issue: ``` File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/fmriprep/config.py", line 810, in dumps settings['execution']['processing_groups'] = _serialize_pg(pg) ^^^^^^^^^^^^^^^^^ File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/fmriprep/config.py", line 870, in _serialize_pg val[1] = [val[1]] ~~~^^^ TypeError: 'tuple' object does not support item assignment ``` should look into adding a sessionwise test to the ci
2 parents 04ef0cf + 7f14d2b commit 33fa78f

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

fmriprep/config.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -848,27 +848,27 @@ def init_spaces(checkpoint=True):
848848
workflow.spaces = spaces
849849

850850

851-
def _serialize_pg(value: list[tuple[str, list[str] | None]]) -> list[str]:
851+
def _serialize_pg(value: list[tuple[str, str | list[str] | None]]) -> list[str]:
852852
"""
853853
Serialize a list of participant-session tuples to be TOML-compatible.
854854
855855
Examples
856856
--------
857-
>>> _serialize_pg([('01', ['pre']), ('01', ['post'])])
857+
>>> _serialize_pg([('01', 'pre'), ('01', ['post'])])
858858
['sub-01_ses-pre', 'sub-01_ses-post']
859859
>>> _serialize_pg([('01', ['pre', 'post']), ('02', ['post'])])
860860
['sub-01_ses-pre,post', 'sub-02_ses-post']
861861
>>> _serialize_pg([('01', None), ('02', ['pre'])])
862862
['sub-01', 'sub-02_ses-pre']
863863
"""
864864
serial = []
865-
for val in value:
866-
if val[1] is None:
867-
serial.append(f'sub-{val[0]}')
868-
else:
869-
if not isinstance(val[1], list):
870-
val[1] = [val[1]]
871-
serial.append(f'sub-{val[0]}_ses-{",".join(val[1])}')
865+
for sub, ses in value:
866+
if ses is None:
867+
serial.append(f'sub-{sub}')
868+
continue
869+
if isinstance(ses, str):
870+
ses = [ses]
871+
serial.append(f'sub-{sub}_ses-{",".join(ses)}')
872872
return serial
873873

874874

@@ -887,12 +887,9 @@ def _deserialize_pg(value: list[str]) -> list[tuple[str, list[str] | None]]:
887887
"""
888888
deserial = []
889889
for val in value:
890-
vals = val.split('_', 1)
891-
vals[0] = vals[0].removeprefix('sub-')
892-
if len(vals) == 1:
893-
vals.append(None)
894-
else:
895-
vals[1] = vals[1].removeprefix('ses-')
896-
vals[1] = vals[1].split(',')
897-
deserial.append(tuple(vals))
890+
sub, _, ses = val.partition('_')
891+
sub = sub.removeprefix('sub-')
892+
if ses:
893+
ses = ses.removeprefix('ses-').split(',')
894+
deserial.append((sub, ses or None))
898895
return deserial

0 commit comments

Comments
 (0)