Clone a key from a Dask collection, producing a new key with the same prefix and indices and a token which is a deterministic function of the previous key and seed. Examples -------- >>> clone_key("x", 123) # doctest: +SKIP 'x-c4fb64ccca807af85082413d7ef01721' >>> clone_key
(key: KeyOrStrT, seed: Hashable)
| 1285 | |
| 1286 | |
| 1287 | def clone_key(key: KeyOrStrT, seed: Hashable) -> KeyOrStrT: |
| 1288 | """Clone a key from a Dask collection, producing a new key with the same prefix and |
| 1289 | indices and a token which is a deterministic function of the previous key and seed. |
| 1290 | |
| 1291 | Examples |
| 1292 | -------- |
| 1293 | >>> clone_key("x", 123) # doctest: +SKIP |
| 1294 | 'x-c4fb64ccca807af85082413d7ef01721' |
| 1295 | >>> clone_key("inc-cbb1eca3bafafbb3e8b2419c4eebb387", 123) # doctest: +SKIP |
| 1296 | 'inc-bc629c23014a4472e18b575fdaf29ee7' |
| 1297 | >>> clone_key(("sum-cbb1eca3bafafbb3e8b2419c4eebb387", 4, 3), 123) # doctest: +SKIP |
| 1298 | ('sum-c053f3774e09bd0f7de6044dbc40e71d', 4, 3) |
| 1299 | """ |
| 1300 | if isinstance(key, tuple) and key and isinstance(key[0], str): |
| 1301 | return (clone_key(key[0], seed),) + key[1:] |
| 1302 | if isinstance(key, str): |
| 1303 | prefix = key_split(key) |
| 1304 | token = tokenize(key, seed) |
| 1305 | return f"{prefix}-{token}" |
| 1306 | raise TypeError(f"Expected str or a tuple starting with str; got {key!r}") |
searching dependent graphs…