From e1fdf90113e1d21bdab7d34c45497bec84ccd48b Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 5 May 2024 17:20:17 +0200 Subject: [PATCH] STY: Apply ruff/refurb rule FURB118 FURB118 Use `operator.pow` instead of defining a function --- nipype/pipeline/engine/tests/test_join.py | 6 ++---- nipype/pipeline/engine/utils.py | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/nipype/pipeline/engine/tests/test_join.py b/nipype/pipeline/engine/tests/test_join.py index 2fe5f70564..da24adee37 100644 --- a/nipype/pipeline/engine/tests/test_join.py +++ b/nipype/pipeline/engine/tests/test_join.py @@ -2,6 +2,7 @@ # vi: set ft=python sts=4 ts=4 sw=4 et: """Tests for join expansion """ +import operator import pytest from .... import config @@ -640,14 +641,11 @@ def sq(x): def test_join_nestediters(tmpdir): tmpdir.chdir() - def exponent(x, p): - return x**p - wf = pe.Workflow("wf", base_dir=tmpdir.strpath) xs = pe.Node(IdentityInterface(["x"]), iterables=[("x", [1, 2])], name="xs") ps = pe.Node(IdentityInterface(["p"]), iterables=[("p", [3, 4])], name="ps") - exp = pe.Node(Function(function=exponent), name="exp") + exp = pe.Node(Function(function=operator.pow), name="exp") exp_joinx = pe.JoinNode( Merge(1, ravel_inputs=True), name="exp_joinx", diff --git a/nipype/pipeline/engine/utils.py b/nipype/pipeline/engine/utils.py index d947735cb0..40994dcc80 100644 --- a/nipype/pipeline/engine/utils.py +++ b/nipype/pipeline/engine/utils.py @@ -4,6 +4,7 @@ import os import sys import pickle +import operator from collections import defaultdict import re from copy import deepcopy @@ -612,7 +613,7 @@ def count_iterables(iterables, synchronize=False): Otherwise, the count is the product of the iterables value list sizes. """ - op = max if synchronize else lambda x, y: x * y + op = max if synchronize else operator.mul return reduce(op, [len(func()) for _, func in list(iterables.items())])