p

    Philip MacMenamin

    4 months ago
    from prefect import task, Flow
    from typing import Tuple
    @task
    def double_and_triple(x: int) -> Tuple[int, int]:
    return x * 2, x * 3
    with Flow("This works") as flow:
    a = [1,2,3]
    double, triple = double_and_triple.map(x=a)
    returns:
    Traceback (most recent call last):
      File "test_mult_ret.py", line 11, in <module>
        double, triple = double_and_triple.map(x=a)
      File "/home/macmenaminpe/.local/lib/python3.8/site-packages/prefect/core/task.py", line 1034, in __iter__
        raise TypeError(
    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.
    (same if:
    @task(nout=2)
    Anna Geller

    Anna Geller

    4 months ago
    nout is the right approach here. But it doesn't work with mapped tasks, check this open issue
    p

    Philip MacMenamin

    4 months ago
    Is the work around to just bundle your return into an object and return that? Or is there a nicer way of doing things?
    Hmm.. this works, but I guess that extra
    zip_task
    task might be nicer.
    Kevin Kho

    Kevin Kho

    4 months ago
    Yeah you need to bundle it as a list or dict. A
    zip_task
    is not quite the right concept. The
    double_and_triple
    task returns a
    Tuple
    so mapping returns a
    List[Tuple]
    . So if you map over 10 items, you get 10 Tuples.
    x, y = something
    in Python means that iterable has 2 items. It assumed the output type is
    Tuple[List]