Clone selected keys in the layer, as well as references to keys in other layers Parameters ---------- keys Keys to be replaced. This never includes keys not listed by :meth:`get_output_keys`. It must also include any keys that are outside
(
self,
keys: set,
seed: Hashable,
bind_to: Key | None = None,
)
| 199 | return keys_in_tasks(all_hlg_keys, [self[key]]) |
| 200 | |
| 201 | def clone( |
| 202 | self, |
| 203 | keys: set, |
| 204 | seed: Hashable, |
| 205 | bind_to: Key | None = None, |
| 206 | ) -> tuple[Layer, bool]: |
| 207 | """Clone selected keys in the layer, as well as references to keys in other |
| 208 | layers |
| 209 | |
| 210 | Parameters |
| 211 | ---------- |
| 212 | keys |
| 213 | Keys to be replaced. This never includes keys not listed by |
| 214 | :meth:`get_output_keys`. It must also include any keys that are outside |
| 215 | of this layer that may be referenced by it. |
| 216 | seed |
| 217 | Common hashable used to alter the keys; see :func:`dask.base.clone_key` |
| 218 | bind_to |
| 219 | Optional key to bind the leaf nodes to. A leaf node here is one that does |
| 220 | not reference any replaced keys; in other words it's a node where the |
| 221 | replacement graph traversal stops; it may still have dependencies on |
| 222 | non-replaced nodes. |
| 223 | A bound node will not be computed until after ``bind_to`` has been computed. |
| 224 | |
| 225 | Returns |
| 226 | ------- |
| 227 | - New layer |
| 228 | - True if the ``bind_to`` key was injected anywhere; False otherwise |
| 229 | |
| 230 | Notes |
| 231 | ----- |
| 232 | This method should be overridden by subclasses to avoid materializing the layer. |
| 233 | """ |
| 234 | from dask.graph_manipulation import chunks |
| 235 | |
| 236 | is_leaf: bool |
| 237 | |
| 238 | def clone_value(o): |
| 239 | """Variant of distributed.utils_comm.subs_multiple, which allows injecting |
| 240 | bind_to |
| 241 | """ |
| 242 | nonlocal is_leaf |
| 243 | |
| 244 | typ = type(o) |
| 245 | if typ is tuple and o and callable(o[0]): |
| 246 | return (o[0],) + tuple(clone_value(i) for i in o[1:]) |
| 247 | elif typ is list: |
| 248 | return [clone_value(i) for i in o] |
| 249 | elif typ is dict: |
| 250 | return {k: clone_value(v) for k, v in o.items()} |
| 251 | else: |
| 252 | try: |
| 253 | if o not in keys: |
| 254 | return o |
| 255 | except TypeError: |
| 256 | return o |
| 257 | is_leaf = False |
| 258 | return clone_key(o, seed) |
nothing calls this directly
no test coverage detected