MCPcopy Create free account
hub / github.com/dask/dask / clone_key

Function clone_key

dask/base.py:1406–1425  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1404
1405
1406def 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}")

Callers 7

clone_valueMethod · 0.90
cloneMethod · 0.90
_bind_oneFunction · 0.90
cloneMethod · 0.90
test_clone_keyFunction · 0.90
test_bindFunction · 0.90

Calls 2

key_splitFunction · 0.90
tokenizeFunction · 0.90

Tested by 3

test_clone_keyFunction · 0.72
test_bindFunction · 0.72