Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Support lists in bids filter file containing null or * #3215

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@
def _drop_sub(value):
return value[4:] if value.startswith("sub-") else value

def _filter_pybids_none_any(dct):
def _process_value(value):
import bids

return {
k: bids.layout.Query.NONE if v is None else (bids.layout.Query.ANY if v == "*" else v)
for k, v in dct.items()
}
if value is None:
return bids.layout.Query.NONE
elif value == "*":
return bids.layout.Query.ANY

Check warning on line 99 in fmriprep/cli/parser.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/cli/parser.py#L96-L99

Added lines #L96 - L99 were not covered by tests
else:
return value

Check warning on line 101 in fmriprep/cli/parser.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/cli/parser.py#L101

Added line #L101 was not covered by tests

def _filter_pybids_none_any(dct):
d = {}
for k, v in dct.items():
if isinstance(v, list):
d[k] = [_process_value(val) for val in v]

Check warning on line 107 in fmriprep/cli/parser.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/cli/parser.py#L104-L107

Added lines #L104 - L107 were not covered by tests
else:
d[k] = _process_value(v)
return d

Check warning on line 110 in fmriprep/cli/parser.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/cli/parser.py#L109-L110

Added lines #L109 - L110 were not covered by tests

def _bids_filter(value, parser):
from json import JSONDecodeError, loads
Expand Down
17 changes: 13 additions & 4 deletions fmriprep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,21 @@
if cls.bids_filters:
from bids.layout import Query

def _process_value(value):
"""Convert string with "Query" in it to Query object."""
if isinstance(value, list):
return [_process_value(val) for val in value]

Check warning on line 499 in fmriprep/config.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/config.py#L499

Added line #L499 was not covered by tests
else:
return (
getattr(Query, value[7:-4])
if not isinstance(value, Query) and "Query" in value
else value
)

# unserialize pybids Query enum values
for acq, filters in cls.bids_filters.items():
cls.bids_filters[acq] = {
k: getattr(Query, v[7:-4]) if not isinstance(v, Query) and "Query" in v else v
for k, v in filters.items()
}
for k, v in filters.items():
cls.bids_filters[acq][k] = _process_value(v)

if "all" in cls.debug:
cls.debug = list(DEBUG_MODES)
Expand Down