From 0f24374e4fdbf67bfea4bf825a50b54c2432d650 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:53:07 +0100 Subject: [PATCH 1/4] STY: Apply ruff/flake8-simplify rule SIM110 SIM110 Use `return any(...)` instead of `for` loop --- niworkflows/utils/spaces.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/niworkflows/utils/spaces.py b/niworkflows/utils/spaces.py index eb82851bd7c..e44dab9b26f 100644 --- a/niworkflows/utils/spaces.py +++ b/niworkflows/utils/spaces.py @@ -521,10 +521,7 @@ def __contains__(self, item): if not self.references: return False item = self.check_space(item) - for s in self.references: - if s == item: - return True - return False + return any(s == item for s in self.references) def __str__(self): """ @@ -730,10 +727,7 @@ def __call__(self, parser, namespace, values, option_string=None): def hasspec(value, specs): """Check whether any of the keys are in a dict.""" - for s in specs: - if s in value: - return True - return False + return any(s in value for s in specs) def format_reference(in_tuple): From 24d6360f35f422c8c2bb498190cc01c7d60da80d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:54:02 +0100 Subject: [PATCH 2/4] STY: Apply ruff/flake8-simplify rule SIM118 SIM118 Use `key in dict` instead of `key in dict.keys()` --- niworkflows/interfaces/bids.py | 4 +--- niworkflows/interfaces/surf.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/niworkflows/interfaces/bids.py b/niworkflows/interfaces/bids.py index ec7131dff3a..3eefaa76c2e 100644 --- a/niworkflows/interfaces/bids.py +++ b/niworkflows/interfaces/bids.py @@ -216,9 +216,7 @@ def _run_interface(self, runtime): except ValueError: pass params = parse_file_entities(in_file) - self._results = { - key: params.get(key, Undefined) for key in _BIDSInfoOutputSpec().get().keys() - } + self._results = {key: params.get(key, Undefined) for key in _BIDSInfoOutputSpec().get()} return runtime diff --git a/niworkflows/interfaces/surf.py b/niworkflows/interfaces/surf.py index 2a1fd76da21..ed01426f1bb 100644 --- a/niworkflows/interfaces/surf.py +++ b/niworkflows/interfaces/surf.py @@ -182,7 +182,7 @@ def _outputs(self): trait_change_notify=False, **{ entity: Undefined - for entity in self._pattern.groupindex.keys() + for entity in self._pattern.groupindex if entity not in self._excluded }, ) From 4f933bdedb2ce6a37835f7ec01d87a80bf7bd040 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:56:00 +0100 Subject: [PATCH 3/4] STY: Apply ruff/flake8-simplify rule SIM211 SIM211 Use `not ...` instead of `False if ... else True` --- niworkflows/reports/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/niworkflows/reports/core.py b/niworkflows/reports/core.py index d954fa34c97..353d77cb9ca 100644 --- a/niworkflows/reports/core.py +++ b/niworkflows/reports/core.py @@ -463,8 +463,7 @@ def _process_orderings(orderings, layout): ] # if all values are None for an entity, we do not want to keep that entity keep_idx = [ - False if (len(val_set) == 1 and None in val_set) or not val_set else True - for val_set in unique_values + not (len(val_set) == 1 and None in val_set or not val_set) for val_set in unique_values ] # the "kept" entities entities = list(compress(orderings, keep_idx)) From cb5e27011d47d6173acf9e314da3100a85860158 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:56:46 +0100 Subject: [PATCH 4/4] STY: Apply ruff/flake8-simplify rule SIM401 SIM401 Use `.get(..., ...)` instead of an `if` block --- niworkflows/utils/timeseries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/niworkflows/utils/timeseries.py b/niworkflows/utils/timeseries.py index d66b11cd726..3ac00b22350 100644 --- a/niworkflows/utils/timeseries.py +++ b/niworkflows/utils/timeseries.py @@ -42,7 +42,7 @@ def _cifti_timeseries(dataset): } seg = {label: [] for label in list(labels.values()) + ['Other']} for bm in matrix.get_index_map(1).brain_models: - label = 'Other' if bm.brain_structure not in labels else labels[bm.brain_structure] + label = labels.get(bm.brain_structure, 'Other') seg[label] += list(range(bm.index_offset, bm.index_offset + bm.index_count)) return dataset.get_fdata(dtype='float32').T, seg