Amit Gal
03/25/2021, 2:11 PMfrom prefect import Flow, task
@task()
def some_task(x):
return x+1
some_list = [1, 2, 3, 4]
with Flow("list_comp") as list_comp_flow:
mapped_result = some_task.map(some_list)
list_comp = [result+1 for result in mapped_result]
results in the following error:
TypeError: Task is not iterable. If your task returns multiple results, pass `nout` to the task decorator/constructor, or provide a `Tuple` return-type annotation to your task.
Which makes sense of course, since while building the flow, mapped_result
is still a Task
, not a list
.Samuel Hinton
03/25/2021, 2:12 PMmap(some_task, some_list)
instead of the other way around?Amit Gal
03/25/2021, 2:20 PMSamuel Hinton
03/25/2021, 2:23 PMAmit Gal
03/25/2021, 2:26 PMfrom prefect import Flow, task
@task()
def some_task(x):
return x+1
@task
def list_comprehension(original_list, lambda_func):
return [lambda_func(x) for x in original_list]
some_list = [1, 2, 3, 4]
with Flow("list_comp") as list_comp_flow:
mapped_result = some_task.map(some_list)
list_comp = list_comprehension(mapped_result, lambda x: x+2)
Amit Gal
03/25/2021, 2:27 PMKevin Kho
task()
call since the decorator is just syntactic sugar for the same thing
from prefect import Flow, task
@task()
def some_task(x):
return x+1
some_list = [1, 2, 3, 4]
with Flow("list_comp") as list_comp_flow:
mapped_result = some_task.map(some_list)
list_comp = task(lambda x: x+1).map(mapped_result)
Kevin Kho
Amit Gal
03/25/2021, 2:40 PMKevin Kho
list_comprehension
one task while this makes another map
operation.