API Reference#
Core functions#
- dags.concatenate_functions(functions, targets=None, return_type='tuple', aggregator=None, enforce_signature=True)[source]
Combine functions to one function that generates targets.
Functions can depend on the output of other functions as inputs, as long as the dependencies can be described by a directed acyclic graph (DAG).
Functions that are not required to produce the targets will simply be ignored.
The arguments of the combined function are all arguments of relevant functions that are not themselves function names, in alphabetical order.
- Parameters
functions (dict or list) – Dict or list of functions. If a list, the function name is inferred from the __name__ attribute of the entries. If a dict, the name of the function is set to the dictionary key.
targets (str or list or None) – Name of the function that produces the target or list of such function names. If the value is None, all variables are returned.
return_type (str) – One of “tuple”, “list”, “dict”. This is ignored if the targets are a single string or if an aggregator is provided.
aggregator (callable or None) – Binary reduction function that is used to aggregate the targets into a single target.
enforce_signature (bool) – If True, the signature of the concatenated function is enforced. Otherwise it is only provided for introspection purposes. Enforcing the signature has a small runtime overhead.
- Returns
A function that produces targets when called with suitable arguments.
- Return type
function
- dags.get_ancestors(functions, targets, include_targets=False)[source]
Build a DAG and extract all ancestors of targets.
- Parameters
functions (dict or list) – Dict or list of functions. If a list, the function name is inferred from the __name__ attribute of the entries. If a dict, with node names as keys or just the values as a tuple for multiple outputs.
targets (str) – Name of the function that produces the target function.
include_targets (bool) – Whether to include the target as its own ancestor.
- Returns
The ancestors
- Return type
Signature tools#
- dags.signature.create_signature(args=None, kwargs=None)[source]
Create a inspect.Signature object based on args and kwargs.
- dags.signature.with_signature(func=None, *, args=None, kwargs=None, enforce=True)[source]
Decorator that adds a signature to a function of type
f(*args, **kwargs)
Caveats: The created signature only contains the names of arguments and whether they are keyword only. There is no way of setting default values, type hints or other things.
- Parameters
func (callable) – The function to be decorated. Should take
*args
and**kwargs
as only arguments.args (list or None) – The names of positional or keyword arguments.
kwargs (list or None) – The keyword only arguments.
enforce (bool) – Whether the signature should be enforced or just added to the function for introspection. This creates runtime overhead.
- Returns
The function with signature.
- Return type
function
- dags.signature.rename_arguments(func=None, *, mapper=None)[source]
Rename positional and keyword arguments of func.
- Parameters
func (callable) – The function of which the arguments are renamed.
mapper (dict) – Dict of strings where keys are old names and values are new of arguments.
- Returns
The function with renamed arguments.
- Return type
function
Internals#
The following documents are auto-generated and not carefully edited. They provide direct access to the source code and the docstrings.