()
| 2034 | |
| 2035 | |
| 2036 | def test_coerce(): |
| 2037 | d0 = da.from_array(np.array(1), chunks=(1,)) |
| 2038 | d1 = da.from_array(np.array([1]), chunks=(1,)) |
| 2039 | with dask.config.set(scheduler="sync"): |
| 2040 | for d in d0, d1: |
| 2041 | assert bool(d) is True |
| 2042 | assert int(d) == 1 |
| 2043 | assert float(d) == 1.0 |
| 2044 | assert complex(d) == complex(1) |
| 2045 | |
| 2046 | a2 = np.arange(2) |
| 2047 | d2 = da.from_array(a2, chunks=(2,)) |
| 2048 | for func in (int, float, complex): |
| 2049 | pytest.raises(TypeError, lambda func=func: func(d2)) |
| 2050 | |
| 2051 | |
| 2052 | def test_bool(): |