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

Function key_split

dask/utils.py:1948–2002  ·  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

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