Skip to content

Commit a53be6f

Browse files
committed
changing the combined result structure - if the result is full combined (i.e. nothing left in the splitter), than removing the nested structure of the output list, and returnin res[0]
1 parent a669a72 commit a53be6f

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed

pydra/engine/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,11 @@ def _combined_output(self):
538538
if result is None:
539539
return None
540540
combined_results[gr].append(result)
541-
return combined_results
541+
if len(combined_results) == 1 and self.state.splitter_rpn_final == []:
542+
# in case it's full combiner, removing the nested structure
543+
return combined_results[0]
544+
else:
545+
return combined_results
542546

543547
def result(self, state_index=None):
544548
"""

pydra/engine/tests/test_node_task.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,10 @@ def test_task_state_comb_1(plugin):
937937
# checking the results
938938
results = nn.result()
939939

940-
combined_results = [[res.output.out for res in res_l] for res_l in results]
941-
expected = [({}, [5, 7])]
942-
for i, res in enumerate(expected):
943-
assert combined_results[i] == res[1]
940+
# fully combined (no nested list)
941+
combined_results = [res.output.out for res in results]
942+
943+
assert combined_results == [5, 7]
944944
# checking the output_dir
945945
assert nn.output_dir
946946
for odir in nn.output_dir:
@@ -1072,11 +1072,11 @@ def test_task_state_comb_singl_1(plugin):
10721072
sub(nn)
10731073

10741074
# checking the results
1075-
expected = [({}, [13, 15])]
1075+
expected = ({}, [13, 15])
10761076
results = nn.result()
1077-
combined_results = [[res.output.out for res in res_l] for res_l in results]
1078-
for i, res in enumerate(expected):
1079-
assert combined_results[i] == res[1]
1077+
# full combiner, no nested list
1078+
combined_results = [res.output.out for res in results]
1079+
assert combined_results == expected[1]
10801080
# checking the output_dir
10811081
assert nn.output_dir
10821082
for odir in nn.output_dir:
@@ -1143,7 +1143,8 @@ def test_task_state_comb_order(plugin):
11431143
assert nn_ab.state.combiner == ["NA.a", "NA.b"]
11441144

11451145
results_ab = nn_ab()
1146-
combined_results_ab = [res.output.out for res in results_ab[0]]
1146+
# full combiner, no nested list
1147+
combined_results_ab = [res.output.out for res in results_ab]
11471148
assert combined_results_ab == [13, 15, 23, 25]
11481149

11491150
# combiner with both fields ["b", "a"] - will create the same list as nn_ab
@@ -1156,7 +1157,7 @@ def test_task_state_comb_order(plugin):
11561157
assert nn_ba.state.combiner == ["NA.b", "NA.a"]
11571158

11581159
results_ba = nn_ba()
1159-
combined_results_ba = [res.output.out for res in results_ba[0]]
1160+
combined_results_ba = [res.output.out for res in results_ba]
11601161
assert combined_results_ba == [13, 15, 23, 25]
11611162

11621163

pydra/engine/tests/test_shelltask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ def test_shell_cmd_5(plugin):
174174
assert shelly.cmdline == ["echo nipype", "echo pydra"]
175175
res = shelly(plugin=plugin)
176176

177-
assert res[0][0].output.stdout == "nipype\n"
178-
assert res[0][1].output.stdout == "pydra\n"
177+
assert res[0].output.stdout == "nipype\n"
178+
assert res[1].output.stdout == "pydra\n"
179179

180180

181181
@pytest.mark.parametrize("plugin", Plugins)

pydra/engine/tests/test_workflow.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ def test_wf_st_2(plugin):
532532
sub(wf)
533533

534534
results = wf.result()
535-
# expected: [[({"test7.x": 1}, 3), ({"test7.x": 2}, 4)]]
536-
assert results[0][0].output.out == 3
537-
assert results[0][1].output.out == 4
535+
# expected: [({"test7.x": 1}, 3), ({"test7.x": 2}, 4)]
536+
assert results[0].output.out == 3
537+
assert results[1].output.out == 4
538538
# checking all directories
539539
assert wf.output_dir
540540
for odir in wf.output_dir:
@@ -554,8 +554,8 @@ def test_wf_ndst_2(plugin):
554554
sub(wf)
555555

556556
results = wf.result()
557-
# expected: [[({"test7.x": 1}, 3), ({"test7.x": 2}, 4)]]
558-
assert results.output.out[0] == [3, 4]
557+
# expected: [({"test7.x": 1}, 3), ({"test7.x": 2}, 4)]
558+
assert results.output.out == [3, 4]
559559
assert wf.output_dir.exists()
560560

561561

@@ -625,10 +625,10 @@ def test_wf_st_4(plugin):
625625

626626
results = wf.result()
627627
# expected: [
628-
# [({"test7.x": 1, "test7.y": 11}, 13), ({"test7.x": 2, "test.y": 12}, 26)]
628+
# ({"test7.x": 1, "test7.y": 11}, 13), ({"test7.x": 2, "test.y": 12}, 26)
629629
# ]
630-
assert results[0][0].output.out == 13
631-
assert results[0][1].output.out == 26
630+
assert results[0].output.out == 13
631+
assert results[1].output.out == 26
632632
# checking all directories
633633
assert wf.output_dir
634634
for odir in wf.output_dir:
@@ -652,9 +652,9 @@ def test_wf_ndst_4(plugin):
652652

653653
results = wf.result()
654654
# expected: [
655-
# [({"test7.x": 1, "test7.y": 11}, 13), ({"test7.x": 2, "test.y": 12}, 26)]
655+
# ({"test7.x": 1, "test7.y": 11}, 13), ({"test7.x": 2, "test.y": 12}, 26)
656656
# ]
657-
assert results.output.out[0] == [13, 26]
657+
assert results.output.out == [13, 26]
658658
# checking the output directory
659659
assert wf.output_dir.exists()
660660

@@ -772,7 +772,7 @@ def test_wf_ndst_7(plugin):
772772
sub(wf)
773773

774774
results = wf.result()
775-
assert results.output.out[0] == [11, 22, 33]
775+
assert results.output.out == [11, 22, 33]
776776

777777
# checking the output directory
778778
assert wf.output_dir.exists()
@@ -821,7 +821,7 @@ def test_wf_ndst_9(plugin):
821821
sub(wf)
822822

823823
results = wf.result()
824-
assert results.output.out[0] == [11, 12, 22, 24, 33, 36]
824+
assert results.output.out == [11, 12, 22, 24, 33, 36]
825825

826826
# checking the output directory
827827
assert wf.output_dir.exists()
@@ -1020,13 +1020,13 @@ def test_wf_3nd_st_4(plugin):
10201020
sub(wf)
10211021

10221022
results = wf.result()
1023-
assert len(results) == 1
1024-
assert results[0][0].output.out == 39
1025-
assert results[0][1].output.out == 42
1026-
assert results[0][2].output.out == 52
1027-
assert results[0][3].output.out == 56
1028-
assert results[0][4].output.out == 65
1029-
assert results[0][5].output.out == 70
1023+
assert len(results) == 6
1024+
assert results[0].output.out == 39
1025+
assert results[1].output.out == 42
1026+
assert results[2].output.out == 52
1027+
assert results[3].output.out == 56
1028+
assert results[4].output.out == 65
1029+
assert results[5].output.out == 70
10301030
# checking all directories
10311031
assert wf.output_dir
10321032
for odir in wf.output_dir:
@@ -1056,8 +1056,8 @@ def test_wf_3nd_ndst_4(plugin):
10561056
# assert wf.output_dir.exists()
10571057
results = wf.result()
10581058

1059-
assert len(results.output.out) == 1
1060-
assert results.output.out == [[39, 42, 52, 56, 65, 70]]
1059+
assert len(results.output.out) == 6
1060+
assert results.output.out == [39, 42, 52, 56, 65, 70]
10611061
# checking the output directory
10621062
assert wf.output_dir.exists()
10631063

@@ -1354,8 +1354,8 @@ def test_wf_st_singl_1(plugin):
13541354
sub(wf)
13551355

13561356
results = wf.result()
1357-
assert results[0][0].output.out == 13
1358-
assert results[0][1].output.out == 24
1357+
assert results[0].output.out == 13
1358+
assert results[1].output.out == 24
13591359
# checking all directories
13601360
assert wf.output_dir
13611361
for odir in wf.output_dir:
@@ -1379,7 +1379,7 @@ def test_wf_ndst_singl_1(plugin):
13791379
sub(wf)
13801380

13811381
results = wf.result()
1382-
assert results.output.out[0] == [13, 24]
1382+
assert results.output.out == [13, 24]
13831383
# checking the output directory
13841384
assert wf.output_dir.exists()
13851385

@@ -2735,7 +2735,7 @@ def test_workflow_combine1(tmpdir):
27352735

27362736
assert result.output.out_pow == [1, 1, 4, 8]
27372737
assert result.output.out_iden1 == [[1, 4], [1, 8]]
2738-
assert result.output.out_iden2 == [[[1, 4], [1, 8]]]
2738+
assert result.output.out_iden2 == [[1, 4], [1, 8]]
27392739

27402740

27412741
def test_workflow_combine2(tmpdir):
@@ -2749,7 +2749,7 @@ def test_workflow_combine2(tmpdir):
27492749
result = wf1(plugin="cf")
27502750

27512751
assert result.output.out_pow == [[1, 4], [1, 8]]
2752-
assert result.output.out_iden == [[[1, 4], [1, 8]]]
2752+
assert result.output.out_iden == [[1, 4], [1, 8]]
27532753

27542754

27552755
# testing lzout.all to collect all of the results and let FunctionTask deal with it

0 commit comments

Comments
 (0)