Skip to content

Commit 194a3ba

Browse files
authored
Merge pull request #255 from djarecka/fix/numpy_wfoutput
fixing is_existing_file, so doesn't have problem with arrays (closes #251)
2 parents acc9010 + c646892 commit 194a3ba

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

pydra/engine/helpers_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,11 @@ def is_local_file(f):
535535
return f.type is File and "container_path" not in f.metadata
536536

537537

538-
def is_existing_file(f):
538+
def is_existing_file(value):
539539
""" checking if an object is an existing file"""
540-
if not f:
540+
if value == "":
541541
return False
542542
try:
543-
return Path(f).exists()
543+
return Path(value).exists()
544544
except TypeError:
545545
return False
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import numpy as np
2+
import typing as ty
3+
import importlib
4+
import pytest
5+
6+
from ..submitter import Submitter
7+
from ..core import Workflow
8+
from ...mark import task, annotate
9+
10+
if importlib.util.find_spec("numpy") is None:
11+
pytest.skip("can't find numpy library", allow_module_level=True)
12+
13+
14+
@task
15+
@annotate({"return": {"b": ty.Any}})
16+
def arrayout(val):
17+
return np.array([val, val])
18+
19+
20+
def test_multiout(plugin):
21+
""" testing a simple function that returns a numpy array"""
22+
wf = Workflow("wf", input_spec=["val"], val=[0, 1, 2])
23+
wf.add(arrayout(name="mo", val=wf.lzin.val))
24+
wf.mo.split("val").combine("val")
25+
26+
wf.set_output([("array", wf.mo.lzout.b)])
27+
28+
with Submitter(plugin=plugin, n_procs=2) as sub:
29+
sub(runnable=wf)
30+
31+
results = wf.result(return_inputs=True)
32+
33+
assert results[0] == {"wf.val": [0, 1, 2]}
34+
for el in range(3):
35+
assert np.array_equal(results[1].output.array[el], np.array([el, el]))

0 commit comments

Comments
 (0)