MCPcopy
hub / github.com/dask/dask / delayed

Function delayed

dask/delayed.py:414–647  ·  view source on GitHub ↗

Wraps a function or object to produce a ``Delayed``. ``Delayed`` objects act as proxies for the object they wrap, but all operations on them are done lazily by building up a dask graph internally. Parameters ---------- obj : object The function or object to wrap nam

(obj, name=None, pure=None, nout=None, traverse=True)

Source from the content-addressed store, hash-verified

412
413@curry
414def delayed(obj, name=None, pure=None, nout=None, traverse=True):
415 """Wraps a function or object to produce a ``Delayed``.
416
417 ``Delayed`` objects act as proxies for the object they wrap, but all
418 operations on them are done lazily by building up a dask graph internally.
419
420 Parameters
421 ----------
422 obj : object
423 The function or object to wrap
424 name : Dask key, optional
425 The key to use in the underlying graph for the wrapped object. Defaults
426 to hashing content. Note that this only affects the name of the object
427 wrapped by this call to delayed, and *not* the output of delayed
428 function calls - for that use ``dask_key_name=`` as described below.
429
430 .. note::
431
432 Because this ``name`` is used as the key in task graphs, you should
433 ensure that it uniquely identifies ``obj``. If you'd like to provide
434 a descriptive name that is still unique, combine the descriptive name
435 with :func:`dask.base.tokenize` of the ``array_like``. See
436 :ref:`graphs` for more.
437
438 pure : bool, optional
439 Indicates whether calling the resulting ``Delayed`` object is a pure
440 operation. If True, arguments to the call are hashed to produce
441 deterministic keys. If not provided, the default is to check the global
442 ``delayed_pure`` setting, and fallback to ``False`` if unset.
443 nout : int, optional
444 The number of outputs returned from calling the resulting ``Delayed``
445 object. If provided, the ``Delayed`` output of the call can be iterated
446 into ``nout`` objects, allowing for unpacking of results. By default
447 iteration over ``Delayed`` objects will error. Note, that ``nout=1``
448 expects ``obj`` to return a tuple of length 1, and consequently for
449 ``nout=0``, ``obj`` should return an empty tuple.
450 traverse : bool, optional
451 By default dask traverses builtin python collections looking for dask
452 objects passed to ``delayed``. For large collections this can be
453 expensive. If ``obj`` doesn't contain any dask objects, set
454 ``traverse=False`` to avoid doing this traversal.
455
456 Examples
457 --------
458 Apply to functions to delay execution:
459
460 >>> from dask import delayed
461 >>> def inc(x):
462 ... return x + 1
463
464 >>> inc(10)
465 11
466
467 >>> x = delayed(inc, pure=True)(10)
468 >>> type(x) == Delayed
469 True
470 >>> x.compute()
471 11

Callers 15

checkpointFunction · 0.90
read_bytesFunction · 0.90
text.pyFile · 0.90
read_textFunction · 0.90
from_delayedMethod · 0.90
from_delayedFunction · 0.90
read_avroFunction · 0.90
test_from_delayedFunction · 0.90
isinMethod · 0.90
to_numericFunction · 0.90
_metaMethod · 0.90

Calls 8

is_dask_collectionFunction · 0.90
quoteFunction · 0.90
setClass · 0.85
DelayedLeafClass · 0.85
DelayedClass · 0.85
from_collectionsMethod · 0.80
unpack_collectionsFunction · 0.70
tokenizeFunction · 0.70

Tested by 15

test_from_delayedFunction · 0.72
test_from_delayedFunction · 0.72
test_from_delayed_daskFunction · 0.72
test_mismatching_metaFunction · 0.72
test_from_delayedFunction · 0.72
test_isinFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…