Skip to content

fix: set _id property of cloned node too #2432

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

Merged
merged 3 commits into from
Feb 9, 2018
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: 4 additions & 1 deletion nipype/pipeline/engine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ def clone(self, name):
A clone of node or workflow must have a new name
"""
if name == self.name:
raise ValueError('Cloning requires a new name, "%s" is in use.' % name)
raise ValueError('Cloning requires a new name, "%s" is '
'in use.' % name)
clone = deepcopy(self)
clone.name = name
if hasattr(clone, '_id'):
clone._id = name
return clone

def _check_outputs(self, parameter):
Expand Down
23 changes: 23 additions & 0 deletions nipype/pipeline/engine/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
from ..base import EngineBase
from ....interfaces import base as nib
from ....interfaces import utility as niu
from ... import engine as pe


class InputSpec(nib.TraitedSpec):
Expand Down Expand Up @@ -64,3 +66,24 @@ def test_clone():

with pytest.raises(ValueError):
base.clone('nodename')

def test_clone_node_iterables(tmpdir):
tmpdir.chdir()

def addstr(string):
return ('%s + 2' % string)

subject_list = ['sub-001', 'sub-002']
inputnode = pe.Node(niu.IdentityInterface(fields=['subject']),
name='inputnode')
inputnode.iterables = [('subject', subject_list)]

node_1 = pe.Node(niu.Function(input_names='string',
output_names='string',
function=addstr), name='node_1')
node_2 = node_1.clone('node_2')

workflow = pe.Workflow(name='iter_clone_wf')
workflow.connect([(inputnode, node_1, [('subject', 'string')]),
(node_1, node_2, [('string', 'string')])])
workflow.run()