How to access a wrapped function from a Delayed
object?
#7174
-
I'm trying to retrieve a wrapped function of either a partial or curried function, and so far I can't seem to figure out where dask stores information about the wrapped function when using Here's a code snippet showing what I'm trying to achieve. I included an example with In [37]: import dask
In [38]: import toolz
In [39]: def mul(a, b):
...: return a * b
...:
In [40]: delayed_mul = dask.delayed(mul)
In [41]: curried_mul = toolz.curry(mul)
In [44]: curried_mul.func
Out[44]: <function __main__.mul(a, b)>
In [48]: curried_mul.func.__name__
Out[48]: 'mul' I had hopes that dask was doing the same. Well, nope :( In [50]: delayed_mul.func
Out[50]: Delayed('getattr-469ea79569437ee253de5413f145f0dd')
In [51]: delayed_mul.func.__name__
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-51-3fd5f0aa9560> in <module>
----> 1 delayed_mul.func.__name__
~/opt/miniconda3/envs/xpersist-dev/lib/python3.9/site-packages/dask/delayed.py in __getattr__(self, attr)
661 if attr == "dtype" and self._attr == "dtype":
662 raise AttributeError("Attribute %s not found" % attr)
--> 663 return super().__getattr__(attr)
664
665 @property
~/opt/miniconda3/envs/xpersist-dev/lib/python3.9/site-packages/dask/delayed.py in __getattr__(self, attr)
538 def __getattr__(self, attr):
539 if attr.startswith("_"):
--> 540 raise AttributeError("Attribute {0} not found".format(attr))
541
542 if attr == "visualise":
AttributeError: Attribute __name__ not found |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You should be able to inspect the task graph for the delayed object to get the wrapped function. Something along the lines of In [1]: import dask
In [2]: def mul(a, b):
...: return a * b
...:
In [3]: delayed_mul = dask.delayed(mul)
In [4]: delayed_mul.dask[delayed_mul.key]
Out[4]: <function __main__.mul(a, b)> |
Beta Was this translation helpful? Give feedback.
You should be able to inspect the task graph for the delayed object to get the wrapped function. Something along the lines of