|
9 | 9 | import dask
|
10 | 10 | import numpy as np
|
11 | 11 | import pytest
|
| 12 | +from dask import is_dask_collection |
12 | 13 | from dask.dataframe._compat import PANDAS_GE_210
|
13 | 14 | from dask.dataframe.utils import UNKNOWN_CATEGORIES
|
14 | 15 | from dask.utils import M
|
|
23 | 24 | to_numeric,
|
24 | 25 | to_timedelta,
|
25 | 26 | )
|
26 |
| -from dask_expr._expr import Tuple, are_co_aligned |
| 27 | +from dask_expr._collection import new_collection |
| 28 | +from dask_expr._expr import Expr, Tuple, are_co_aligned |
27 | 29 | from dask_expr._reductions import Len
|
28 | 30 | from dask_expr._shuffle import Shuffle
|
29 | 31 | from dask_expr.datasets import timeseries
|
@@ -1925,3 +1927,20 @@ def test_axes(df, pdf):
|
1925 | 1927 | [assert_eq(d, p) for d, p in zip(df.axes, pdf.axes)]
|
1926 | 1928 | assert len(df.x.axes) == len(pdf.x.axes)
|
1927 | 1929 | assert_eq(df.x.axes[0], pdf.x.axes[0])
|
| 1930 | + |
| 1931 | + |
| 1932 | +def test_dask_collection_controlled_materialization(): |
| 1933 | + class NoMaterializationAllowed(Expr): |
| 1934 | + _meta = int |
| 1935 | + |
| 1936 | + def _layer(self): |
| 1937 | + raise RuntimeError("Materialization not allowed") |
| 1938 | + |
| 1939 | + collection = new_collection(NoMaterializationAllowed()) |
| 1940 | + assert is_dask_collection(collection) |
| 1941 | + |
| 1942 | + with pytest.raises(RuntimeError, match="Materialization not allowed"): |
| 1943 | + collection.dask |
| 1944 | + |
| 1945 | + with pytest.raises(RuntimeError, match="Materialization not allowed"): |
| 1946 | + collection.__dask_graph_factory__().materialize() |
0 commit comments