Get value from Dask Examples -------- >>> inc = lambda x: x + 1 >>> d = {'x': 1, 'y': (inc, 'x')} >>> get(d, 'x') 1 >>> get(d, 'y') 2
(dsk: Mapping, out: list | Key, cache: MutableMapping | None = None)
| 84 | |
| 85 | |
| 86 | def get(dsk: Mapping, out: list | Key, cache: MutableMapping | None = None) -> Any: |
| 87 | """Get value from Dask |
| 88 | |
| 89 | Examples |
| 90 | -------- |
| 91 | |
| 92 | >>> inc = lambda x: x + 1 |
| 93 | >>> d = {'x': 1, 'y': (inc, 'x')} |
| 94 | |
| 95 | >>> get(d, 'x') |
| 96 | 1 |
| 97 | >>> get(d, 'y') |
| 98 | 2 |
| 99 | """ |
| 100 | for k in flatten(out): |
| 101 | if k not in dsk: |
| 102 | raise KeyError(f"{k} is not a key in the graph") |
| 103 | if cache is None: |
| 104 | cache = {} |
| 105 | |
| 106 | dsk2 = convert_legacy_graph(dsk, all_keys=set(dsk) | set(cache)) |
| 107 | result = execute_graph(dsk2, cache, keys=set(flatten([out]))) |
| 108 | return _pack_result(result, out) |
| 109 | |
| 110 | |
| 111 | def keys_in_tasks(keys: Collection[Key], tasks: Iterable[Any], as_list: bool = False): |