Apply a function given its positional and keyword arguments. Equivalent to ``func(*args, **kwargs)`` Most Dask users will never need to use the ``apply`` function. It is typically only used by people who need to inject keyword argument values into a low level Dask task graph. P
(func, args, kwargs=None)
| 45 | |
| 46 | |
| 47 | def apply(func, args, kwargs=None): |
| 48 | """Apply a function given its positional and keyword arguments. |
| 49 | |
| 50 | Equivalent to ``func(*args, **kwargs)`` |
| 51 | Most Dask users will never need to use the ``apply`` function. |
| 52 | It is typically only used by people who need to inject |
| 53 | keyword argument values into a low level Dask task graph. |
| 54 | |
| 55 | Parameters |
| 56 | ---------- |
| 57 | func : callable |
| 58 | The function you want to apply. |
| 59 | args : tuple |
| 60 | A tuple containing all the positional arguments needed for ``func`` |
| 61 | (eg: ``(arg_1, arg_2, arg_3)``) |
| 62 | kwargs : dict, optional |
| 63 | A dictionary mapping the keyword arguments |
| 64 | (eg: ``{"kwarg_1": value, "kwarg_2": value}`` |
| 65 | |
| 66 | Examples |
| 67 | -------- |
| 68 | >>> from dask.utils import apply |
| 69 | >>> def add(number, second_number=5): |
| 70 | ... return number + second_number |
| 71 | ... |
| 72 | >>> apply(add, (10,), {"second_number": 2}) # equivalent to add(*args, **kwargs) |
| 73 | 12 |
| 74 | |
| 75 | >>> task = apply(add, (10,), {"second_number": 2}) |
| 76 | >>> dsk = {'task-name': task} # adds the task to a low level Dask task graph |
| 77 | """ |
| 78 | if kwargs: |
| 79 | return func(*args, **kwargs) |
| 80 | else: |
| 81 | return func(*args) |
| 82 | |
| 83 | |
| 84 | def _deprecated( |