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)
| 1404 | |
| 1405 | |
| 1406 | def clone_key(key: KeyOrStrT, seed: Hashable) -> KeyOrStrT: |
| 1407 | """Clone a key from a Dask collection, producing a new key with the same prefix and |
| 1408 | indices and a token which is a deterministic function of the previous key and seed. |
| 1409 | |
| 1410 | Examples |
| 1411 | -------- |
| 1412 | >>> clone_key("x", 123) # doctest: +SKIP |
| 1413 | 'x-c4fb64ccca807af85082413d7ef01721' |
| 1414 | >>> clone_key("inc-cbb1eca3bafafbb3e8b2419c4eebb387", 123) # doctest: +SKIP |
| 1415 | 'inc-bc629c23014a4472e18b575fdaf29ee7' |
| 1416 | >>> clone_key(("sum-cbb1eca3bafafbb3e8b2419c4eebb387", 4, 3), 123) # doctest: +SKIP |
| 1417 | ('sum-c053f3774e09bd0f7de6044dbc40e71d', 4, 3) |
| 1418 | """ |
| 1419 | if isinstance(key, tuple) and key and isinstance(key[0], str): |
| 1420 | return (clone_key(key[0], seed),) + key[1:] |
| 1421 | if isinstance(key, str): |
| 1422 | prefix = key_split(key) |
| 1423 | token = tokenize(key, seed) |
| 1424 | return f"{prefix}-{token}" |
| 1425 | raise TypeError(f"Expected str or a tuple starting with str; got {key!r}") |