Convert many collections into a single dask expression. Typically, users should not be required to interact with this function. Parameters ---------- collections : Iterable An iterable of dask collections to be combined. optimize_graph : bool, optional If t
(
collections: Iterable,
optimize_graph: bool = True,
)
| 411 | |
| 412 | |
| 413 | def collections_to_expr( |
| 414 | collections: Iterable, |
| 415 | optimize_graph: bool = True, |
| 416 | ) -> Expr: |
| 417 | """ |
| 418 | Convert many collections into a single dask expression. |
| 419 | |
| 420 | Typically, users should not be required to interact with this function. |
| 421 | |
| 422 | Parameters |
| 423 | ---------- |
| 424 | collections : Iterable |
| 425 | An iterable of dask collections to be combined. |
| 426 | optimize_graph : bool, optional |
| 427 | If this is True and collections are encountered which are backed by |
| 428 | legacy HighLevelGraph objects, the returned Expression will run a low |
| 429 | level task optimization during materialization. |
| 430 | """ |
| 431 | is_iterable = False |
| 432 | if isinstance(collections, (tuple, list, set)): |
| 433 | is_iterable = True |
| 434 | else: |
| 435 | collections = [collections] |
| 436 | if not collections: |
| 437 | raise ValueError("No collections provided") |
| 438 | from dask._expr import HLGExpr, _ExprSequence |
| 439 | |
| 440 | graphs = [] |
| 441 | for coll in collections: |
| 442 | from dask.delayed import Delayed |
| 443 | |
| 444 | if isinstance(coll, Delayed) or not hasattr(coll, "expr"): |
| 445 | graphs.append(HLGExpr.from_collection(coll, optimize_graph=optimize_graph)) |
| 446 | else: |
| 447 | graphs.append(coll.expr) |
| 448 | |
| 449 | if len(graphs) > 1 or is_iterable: |
| 450 | return _ExprSequence(*graphs) |
| 451 | else: |
| 452 | return graphs[0] |
| 453 | |
| 454 | |
| 455 | def unpack_collections(*args, traverse=True): |
searching dependent graphs…