1

This code:

@dask.delayed
def sum_nr(a,b):
    return a+b, a, b

for i in range(10):
    sum_ab, a, b = sum_nr(i, i+1)

produces

TypeError: Delayed objects of unspecified length are not iterable

What is a different way of outputting multiple items from a function, in dask?

2 Answers 2

4

I doubt that calling .compute() on delayed output immediately generally makes sense. delayed must be just avoided in those cases.

For those who are facing that issue in situations where a use of delayed is reasonable, there are other options.

Option 1: nout argument

@dask.delayed(nout=3)
def sum_nr(a,b):
    return a+b, a, b

for i in range(10):
    sum_ab, a, b = sum_nr(i, i+1)

# You need to call .compute() on necessary outputs at the end

Option 2: Explicit indexing

@dask.delayed
def sum_nr(a,b):
    return a+b, a, b

for i in range(10):
    res = sum_nr(i, i+1)
    sum_ab, a, b = res[0], res[1], res[2]

# You need to call .compute() on necessary outputs at the end

Sign up to request clarification or add additional context in comments.

1 Comment

I think this should be the accepted answer.
1

You are missing the compute call as specified in the documentation.

for i in range(10):
    sum_ab, a, b = sum_nr(i, i+1).compute()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.