Skip to content

Commit 782a115

Browse files
STY: Apply assorted ruff/refurb rules (#867)
* STY: Apply ruff/refurb rule (FURB118) FURB118 Use `operator.or_` instead of defining a lambda FURB118 Use `operator.add` instead of defining a lambda * STY: Apply ruff/refurb rule (FURB148) FURB148 `enumerate` index is unused, use `for x in y` instead * STY: Apply ruff/refurb rule (FURB168) FURB168 Prefer `is` operator over `isinstance` to check if an object is `None`
1 parent 9f9bf4f commit 782a115

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

niworkflows/interfaces/confounds.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import re
2626
import numpy as np
27+
import operator
2728
import pandas as pd
2829
from functools import reduce
2930
from collections import deque, OrderedDict
@@ -295,7 +296,7 @@ def spike_regressors(
295296
mask[metric] = set(np.where(data[metric] < threshold)[0])
296297
elif criterion == ">":
297298
mask[metric] = set(np.where(data[metric] > threshold)[0])
298-
mask = reduce((lambda x, y: x | y), mask.values())
299+
mask = reduce(operator.or_, mask.values())
299300

300301
for lag in lags:
301302
mask = set([m + lag for m in mask]) | mask
@@ -362,7 +363,7 @@ def temporal_derivatives(order, variables, data):
362363
variables_deriv[o] = ["{}_derivative{}".format(v, o) for v in variables]
363364
data_deriv[o] = np.tile(np.nan, data[variables].shape)
364365
data_deriv[o][o:, :] = np.diff(data[variables], n=o, axis=0)
365-
variables_deriv = reduce((lambda x, y: x + y), variables_deriv.values())
366+
variables_deriv = reduce(operator.add, variables_deriv.values())
366367
data_deriv = pd.DataFrame(
367368
columns=variables_deriv, data=np.concatenate([*data_deriv.values()], axis=1)
368369
)
@@ -404,7 +405,7 @@ def exponential_terms(order, variables, data):
404405
for o in order:
405406
variables_exp[o] = ["{}_power{}".format(v, o) for v in variables]
406407
data_exp[o] = data[variables] ** o
407-
variables_exp = reduce((lambda x, y: x + y), variables_exp.values())
408+
variables_exp = reduce(operator.add, variables_exp.values())
408409
data_exp = pd.DataFrame(
409410
columns=variables_exp, data=np.concatenate([*data_exp.values()], axis=1)
410411
)
@@ -570,7 +571,7 @@ def _unscramble_regressor_columns(parent_data, data):
570571
var[col].appendleft(c)
571572
else:
572573
var[col].append(c)
573-
unscrambled = reduce((lambda x, y: x + y), var.values())
574+
unscrambled = reduce(operator.add, var.values())
574575
return data[[*unscrambled]]
575576

576577

@@ -649,7 +650,7 @@ def parse_formula(model_formula, parent_data, unscramble=False):
649650
(variables[expression], data[expression]) = parse_expression(
650651
expression, parent_data
651652
)
652-
variables = list(set(reduce((lambda x, y: x + y), variables.values())))
653+
variables = list(set(reduce(operator.add, variables.values())))
653654
data = pd.concat((data.values()), axis=1)
654655

655656
if unscramble:

niworkflows/utils/connections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def listify(value):
7171
"""
7272
from pathlib import Path
7373
from nipype.interfaces.base import isdefined
74-
if not isdefined(value) or isinstance(value, type(None)):
74+
if not isdefined(value) or value is None:
7575
return value
7676
if isinstance(value, (str, bytes, Path)):
7777
return [str(value)]

niworkflows/viz/plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def confoundplot(
692692
if cutoff is None:
693693
cutoff = []
694694

695-
for i, thr in enumerate(cutoff):
695+
for thr in cutoff:
696696
ax_ts.plot((0, ntsteps - 1), [thr] * 2, linewidth=0.2, color="dimgray")
697697

698698
ax_ts.annotate(

0 commit comments

Comments
 (0)