Skip to content

Commit db26703

Browse files
authored
Merge pull request #2432 from mgxd/fix/clone
fix: set _id property of cloned node too
2 parents 2c0edaa + e98cf31 commit db26703

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

nipype/pipeline/engine/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ def clone(self, name):
8484
A clone of node or workflow must have a new name
8585
"""
8686
if name == self.name:
87-
raise ValueError('Cloning requires a new name, "%s" is in use.' % name)
87+
raise ValueError('Cloning requires a new name, "%s" is '
88+
'in use.' % name)
8889
clone = deepcopy(self)
8990
clone.name = name
91+
if hasattr(clone, '_id'):
92+
clone._id = name
9093
return clone
9194

9295
def _check_outputs(self, parameter):

nipype/pipeline/engine/tests/test_base.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pytest
77
from ..base import EngineBase
88
from ....interfaces import base as nib
9+
from ....interfaces import utility as niu
10+
from ... import engine as pe
911

1012

1113
class InputSpec(nib.TraitedSpec):
@@ -64,3 +66,24 @@ def test_clone():
6466

6567
with pytest.raises(ValueError):
6668
base.clone('nodename')
69+
70+
def test_clone_node_iterables(tmpdir):
71+
tmpdir.chdir()
72+
73+
def addstr(string):
74+
return ('%s + 2' % string)
75+
76+
subject_list = ['sub-001', 'sub-002']
77+
inputnode = pe.Node(niu.IdentityInterface(fields=['subject']),
78+
name='inputnode')
79+
inputnode.iterables = [('subject', subject_list)]
80+
81+
node_1 = pe.Node(niu.Function(input_names='string',
82+
output_names='string',
83+
function=addstr), name='node_1')
84+
node_2 = node_1.clone('node_2')
85+
86+
workflow = pe.Workflow(name='iter_clone_wf')
87+
workflow.connect([(inputnode, node_1, [('subject', 'string')]),
88+
(node_1, node_2, [('string', 'string')])])
89+
workflow.run()

0 commit comments

Comments
 (0)