Inconsistent handling when iterating Delayed objects with nout=1
- Dominant language
- Python
- Stars
- 13.9k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
The following code causes a slice to be taken from a Delayed object when `_length==1`:
https://github.com/dask/dask/blob/e9845aadc7c32078e55354b61f5626ac759e8b28/dask/delayed.py#L619-L620
Here's a minimal example of the anomalous behavior from the case when nout=1
```python
>>> from dask.delayed import delayed
>>> @delayed(nout=1)
... def ret(x):
... return x
...
>>> @delayed(nout=2)
... def echo(x):
... return x,x
...
>>> d1 = ret([1,2,3])
>>> d2 = echo([1,2,3])
>>> for d in d1:
... print(d.compute())
...
1
>>> for d in d2:
... print(d.compute())
...
[1, 2, 3]
[1, 2, 3]
```
I think the iteration of d1 should be the full output, i.e. [1, 2, 3], instead of just 1.
An inelegant fix could be:
```python
if self._length == 1:
yield self
else:
for i in range(self._length):
yield self[i]
```
Contributor guide
Research direction
Start at dask/delayed.py lines 619-620 and reproduce the nout=1 and nout=2 examples from the issue. Check that iterating a Delayed object with nout=1 yields the complete output, while nout=2 still yields each output separately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100