Skip to content

Commit 01b6e0f

Browse files
committed
Merge pull request #428 from chrisfilo/fix.mapnode_array
Fixed mapnode isdefined bug
2 parents 9a1b545 + 1300f33 commit 01b6e0f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

nipype/interfaces/tests/test_utility.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66

77
from nipype.testing import assert_equal, assert_true
88
from nipype.interfaces import utility
9+
import nipype.pipeline.engine as pe
10+
911

1012
def test_rename():
1113
tempdir = os.path.realpath(mkdtemp())
1214
origdir = os.getcwd()
1315
os.chdir(tempdir)
1416

1517
# Test very simple rename
16-
_ = open("file.txt","w").close()
18+
_ = open("file.txt", "w").close()
1719
rn = utility.Rename(in_file="file.txt", format_string="test_file1.txt")
1820
res = rn.run()
1921
outfile = os.path.join(tempdir, "test_file1.txt")
2022
yield assert_equal, res.outputs.out_file, outfile
2123
yield assert_true, os.path.exists(outfile)
2224

2325
# Now a string-formatting version
24-
rn = utility.Rename(in_file="file.txt", format_string="%(field1)s_file%(field2)d",keep_ext=True)
26+
rn = utility.Rename(in_file="file.txt", format_string="%(field1)s_file%(field2)d", keep_ext=True)
2527
# Test .input field creation
2628
yield assert_true, hasattr(rn.inputs, "field1")
2729
yield assert_true, hasattr(rn.inputs, "field2")
@@ -36,3 +38,31 @@ def test_rename():
3638
# Clean up
3739
os.chdir(origdir)
3840
shutil.rmtree(tempdir)
41+
42+
43+
def test_function():
44+
tempdir = os.path.realpath(mkdtemp())
45+
origdir = os.getcwd()
46+
os.chdir(tempdir)
47+
48+
def gen_random_array(size):
49+
import numpy as np
50+
return np.random.rand(size, size)
51+
52+
f1 = pe.MapNode(utility.Function(input_names=['size'], output_names=['random_array'], function=gen_random_array), name='random_array', iterfield=['size'])
53+
f1.inputs.size = [2, 3, 5]
54+
55+
wf = pe.Workflow(name="test_workflow")
56+
57+
def increment_array(in_array):
58+
return in_array + 1
59+
60+
f2 = pe.MapNode(utility.Function(input_names=['in_array'], output_names=['out_array'], function=increment_array), name='increment_array', iterfield=['in_array'])
61+
62+
wf.connect(f1, 'random_array', f2, 'in_array')
63+
64+
wf.run()
65+
66+
# Clean up
67+
os.chdir(origdir)
68+
shutil.rmtree(tempdir)

nipype/pipeline/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ def _collate_results(self, nodes):
16411641
values.insert(i, node.result.outputs.get()[key])
16421642
else:
16431643
values.insert(i, None)
1644-
if any([val != Undefined for val in values]) and \
1644+
if any([isdefined(val) for val in values]) and \
16451645
self._result.outputs:
16461646
setattr(self._result.outputs, key, values)
16471647
if returncode and any([code is not None for code in returncode]):

0 commit comments

Comments
 (0)