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: Use removeprefix instead of lstrip or ternary operator #3409

Merged
merged 1 commit into from
Dec 11, 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
5 changes: 1 addition & 4 deletions fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ def _to_gb(value):
units = value[len(digits) :] or 'M'
return int(digits) * scale[units[0]]

def _drop_sub(value):
return value[4:] if value.startswith('sub-') else value

def _process_value(value):
import bids

Expand Down Expand Up @@ -205,7 +202,7 @@ def _slice_time_ref(value, parser):
'--participant_label',
action='store',
nargs='+',
type=_drop_sub,
type=lambda label: label.removeprefix('sub-'),
help='A space delimited list of participant identifiers or a single '
'identifier (the sub- prefix can be removed)',
)
Expand Down
8 changes: 4 additions & 4 deletions fmriprep/reports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def generate_reports(

errors = []
for subject_label in subject_list:
subject_label = subject_label.removeprefix('sub-')
# The number of sessions is intentionally not based on session_list but
# on the total number of sessions, because I want the final derivatives
# folder to be the same whether sessions were run one at a time or all-together.
Expand All @@ -95,7 +96,7 @@ def generate_reports(
else:
# Beyond a threshold, we separate the anatomical report from the functional.
bootstrap_file = data.load('reports-spec-anat.yml')
html_report = f'sub-{subject_label.lstrip("sub-")}_anat.html'
html_report = f'sub-{subject_label}_anat.html'

report_error = run_reports(
output_dir,
Expand All @@ -121,12 +122,11 @@ def generate_reports(
subject=subject_label, **filters
)

# Drop ses- prefixes
session_list = [ses[4:] if ses.startswith('ses-') else ses for ses in session_list]
session_list = [ses.removeprefix('ses-') for ses in session_list]

for session_label in session_list:
bootstrap_file = data.load('reports-spec-func.yml')
html_report = f'sub-{subject_label.lstrip("sub-")}_ses-{session_label}_func.html'
html_report = f'sub-{subject_label}_ses-{session_label}_func.html'

report_error = run_reports(
output_dir,
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
# Limit validation only to data from requested participants
if participant_label:
all_subs = {s.name[4:] for s in bids_dir.glob('sub-*')}
selected_subs = {s[4:] if s.startswith('sub-') else s for s in participant_label}
selected_subs = {s.removeprefix('sub-') for s in participant_label}

Check warning on line 220 in fmriprep/utils/bids.py

View check run for this annotation

Codecov / codecov/patch

fmriprep/utils/bids.py#L220

Added line #L220 was not covered by tests
bad_labels = selected_subs.difference(all_subs)
if bad_labels:
error_msg = (
Expand Down
Loading