Skip to content

Commit

Permalink
FIX: Support lists in bids filter file containing null or * (#3215)
Browse files Browse the repository at this point in the history
FIX: Support lists in bids filter file containing `null` or `*`
  • Loading branch information
effigies committed Jan 26, 2024
2 parents 9670513 + e423518 commit 4d21c37
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
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 _to_gb(value):
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
else:
return value

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]
else:
d[k] = _process_value(v)
return d

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 @@ def init(cls):
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]
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

0 comments on commit 4d21c37

Please sign in to comment.