MCPcopy Index your code
hub / github.com/dask/dask / key_split

Function key_split

dask/utils.py:1945–1999  ·  view source on GitHub ↗

>>> key_split('x') 'x' >>> key_split('x-1') 'x' >>> key_split('x-1-2-3') 'x' >>> key_split(('x-2', 1)) 'x' >>> key_split("('x-2', 1)") 'x' >>> key_split("('x', 1)") 'x' >>> key_split('hello-world-1') 'hello-world' >>> key_split(b'hello-wor

(s)

Source from the content-addressed store, hash-verified

1943
1944@functools.lru_cache(100000)
1945def key_split(s):
1946 """
1947 >>> key_split('x')
1948 'x'
1949 >>> key_split('x-1')
1950 'x'
1951 >>> key_split('x-1-2-3')
1952 'x'
1953 >>> key_split(('x-2', 1))
1954 'x'
1955 >>> key_split("('x-2', 1)")
1956 'x'
1957 >>> key_split("('x', 1)")
1958 'x'
1959 >>> key_split('hello-world-1')
1960 'hello-world'
1961 >>> key_split(b'hello-world-1')
1962 'hello-world'
1963 >>> key_split('ae05086432ca935f6eba409a8ecd4896')
1964 'data'
1965 >>> key_split('<module.submodule.myclass object at 0xdaf372')
1966 'myclass'
1967 >>> key_split(None)
1968 'Other'
1969 >>> key_split('x-abcdefab') # ignores hex
1970 'x'
1971 >>> key_split('_(x)') # strips unpleasant characters
1972 'x'
1973 """
1974 # If we convert the key, recurse to utilize LRU cache better
1975 if type(s) is bytes:
1976 return key_split(s.decode())
1977 if type(s) is tuple:
1978 return key_split(s[0])
1979 try:
1980 words = s.split("-")
1981 if not words[0][0].isalpha():
1982 result = words[0].split(",")[0].strip("_'()\"")
1983 else:
1984 result = words[0]
1985 for word in words[1:]:
1986 if word.isalpha() and not (
1987 len(word) == 8 and hex_pattern.match(word) is not None
1988 ):
1989 result += f"-{word}"
1990 else:
1991 break
1992 if len(result) == 32 and re.match(r"[a-f0-9]{32}", result):
1993 return "data"
1994 else:
1995 if result[0] == "<":
1996 result = result.strip("<>").split()[0].split(".")[-1]
1997 return sys.intern(result)
1998 except Exception:
1999 return "Other"
2000
2001
2002def stringify(obj, exclusive: Iterable | None = None):

Callers 15

to_graphvizFunction · 0.90
_to_cytoscape_jsonFunction · 0.90
_repr_html_Method · 0.90
clone_keyFunction · 0.90
__str__Method · 0.90
__repr__Method · 0.90
__dask_postpersist__Method · 0.90
from_dask_arrayFunction · 0.90
optimize_doubleFunction · 0.90
test_clone_keyFunction · 0.90
test_reprFunction · 0.90

Calls 2

splitMethod · 0.80
matchMethod · 0.80

Tested by 8

optimize_doubleFunction · 0.72
test_clone_keyFunction · 0.72
test_reprFunction · 0.72
test_namesFunction · 0.72
test_anom_meanFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…