Q: Stack overflow on dask __array__ I have a rather simple program using dask:
import dask.array as darray
import numpy as np

X = np.array([[1.,2.,3.],
              [4.,5.,6.],
              [7.,8.,9.]])
arr = darray.from_array(X)
arr = arr[:,0]
a = darray.min(arr)
b = darray.max(arr)
quantiles = darray.linspace(a, b, 4)
print(np.array(quantiles))

Running this program results in an error like this:
Traceback (most recent call last):
  File "discretization.py", line 12, in <module>
    print(np.array(quantiles))
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/array/core.py", line 1341, in __array__
    x = np.array(x)
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/array/core.py", line 1341, in __array__
    x = np.array(x)
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/array/core.py", line 1341, in __array__
    x = np.array(x)
  [Previous line repeated 325 more times]
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/array/core.py", line 1337, in __array__
    x = self.compute()
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/base.py", line 166, in compute
    (result,) = compute(self, traverse=False, **kwargs)
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/base.py", line 434, in compute
    dsk = collections_to_dsk(collections, optimize_graph, **kwargs)
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/base.py", line 220, in collections_to_dsk
    [opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()],
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/base.py", line 220, in <listcomp>
    [opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()],
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/array/optimization.py", line 42, in optimize
    dsk = optimize_blockwise(dsk, keys=keys)
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/blockwise.py", line 547, in optimize_blockwise
    out = _optimize_blockwise(graph, keys=keys)
  File "/Users/zhujun/job/adf/local_training/venv/lib/python3.7/site-packages/dask/blockwise.py", line 572, in _optimize_blockwise
    if isinstance(layers[layer], Blockwise):
  File "/anaconda3/lib/python3.7/abc.py", line 139, in __instancecheck__
    return _abc_instancecheck(cls, instance)
RecursionError: maximum recursion depth exceeded in comparison

Python is version 3.7.1 and dask is version 2.15.0.
What is wrong with this program?
Thanks in advance.

A: linspace does not (yet) accept lazy inputs from other dask things, you need real numbers. Use compute to materialize these numbers as follows:
a, b = dask.compute(darray.min(arr),  darray.max(arr))
quantiles = darray.linspace(a, b, 4)


A: With either one of these package combinations:
dask==2.15.0
numpy<1.16.0
toolz==0.9.0

dask==2.16.0
numpy<1.17.0
toolz==0.9.0

The following program can be executed without an issue:
import dask.array as darray
import numpy as np

X = np.array([[1.,2.,3.],
              [4.,5.,6.],
              [7.,8.,9.]])
arr = darray.from_array(X)
arr = arr[:,0]
a = darray.min(arr)
b = darray.max(arr)

q0 = darray.linspace(a, b, 4)
print(np.array(q0))

The key in the above package lists is numpy. Newer versions of numpy may cause an error.
As @mdurant suggested, the implementation of linspace does not yet accept lazy inputs; hence the fact that these combinations of packages work might be actually an coincidence.
I will leave this question open until I fully understand what is happening here.
