[docs]defcull(dsk,keys):"""Like :func:`dask.optimization.cull`. This version calls :func:`.to_keylike` on the culled graph and dependencies to ensure the resulting graph does not contain :class:`.Key`. """importdask.optimizationout0,dependencies0=dask.optimization.cull(dsk,keys)# Rewrite Key to str in out0out1={to_keylike(k):to_keylike(task)fork,taskinout0.items()}# Rewrite Key to str in dependencies0dependencies1={to_keylike(k):to_keylike(deps)fork,depsinout0.items()}returnout1,dependencies1
[docs]defto_keylike(value):"""Rewrite :class:`.Key` `value` (or in `value`) to :class:`.str`. Collections such as :class:`tuple` and :class:`list` are rewritten recursively. """fromgenno.core.keyimportKeyifisinstance(value,(str,bytes,int,float)):# These are the strict types of dask.typing.Key (also tuple of same).# Return as-is without further checksreturnvalueelifisinstance(value,Key):returnstr(value)eliftype(value)in(tuple,list):# NB Only exactly these types; not subclassesreturntype(value)(map(to_keylike,value))# Recurse; return same typeelse:returnvalue