Skip to content

Commit 0f43e66

Browse files
committed
ENH: Add Select task
1 parent 184ca63 commit 0f43e66

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pydra/tasks/core/sequences.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import attr
22
import typing as ty
3-
from pydra.engine.specs import BaseSpec, SpecInfo
3+
import pydra
4+
from pydra.engine.specs import BaseSpec, SpecInfo, MultiInputObj, MultiOutputObj
45
from pydra.engine.core import TaskBase
56
from pydra.engine.helpers import ensure_list
67

@@ -117,3 +118,28 @@ def _run_task(self):
117118
self.output_["out"] = [
118119
[val[i] for val in lists] for i in range(len(lists[0]))
119120
]
121+
122+
123+
@pydra.mark.task
124+
def Select(inlist: MultiInputObj, index: MultiInputObj) -> MultiOutputObj:
125+
"""
126+
Task to select specific elements from a list
127+
128+
Examples
129+
--------
130+
131+
>>> from pydra.tasks.core.sequences import Select
132+
>>> sl = Select(name="sl")
133+
>>> sl.inputs.inlist = [1, 2, 3, 4, 5]
134+
>>> sl.inputs.index = [3]
135+
>>> out = sl()
136+
>>> out.output.out
137+
4
138+
139+
>>> sl = Select(name="sl")
140+
>>> out = sl(inlist=[1, 2, 3, 4, 5], index=[3, 4])
141+
>>> out.output.out
142+
[4, 5]
143+
144+
"""
145+
return [inlist[i] for i in index]

0 commit comments

Comments
 (0)