does#
@does
is a decorator that essentially allows you to run a function over all the input parameters. So you can’t pass
any old function to @does
, instead the function passed has to take any amount of inputs and process them all in the
same way.
import pandas as pd
from hamilton.function_modifiers import does
import internal_package_with_logic
def sum_series(**series: pd.Series) -> pd.Series:
"""This function takes any number of inputs and sums them all together."""
...
@does(sum_series)
def D_XMAS_GC_WEIGHTED_BY_DAY(D_XMAS_GC_WEIGHTED_BY_DAY_1: pd.Series,
D_XMAS_GC_WEIGHTED_BY_DAY_2: pd.Series) -> pd.Series:
"""Adds D_XMAS_GC_WEIGHTED_BY_DAY_1 and D_XMAS_GC_WEIGHTED_BY_DAY_2"""
pass
@does(internal_package_with_logic.identity_function)
def copy_of_x(x: pd.Series) -> pd.Series:
"""Just returns x"""
pass
The example here is a function, that all that it does, is sum all the parameters together. So we can annotate it with
the @does
decorator and pass it the sum_series
function. The @does
decorator is currently limited to just
allow functions that consist only of one argument, a generic **kwargs.
Reference Documentation
- class hamilton.function_modifiers.does(replacing_function: Callable, **argument_mapping: str | List[str])#
@does
is a decorator that essentially allows you to run a function over all the input parameters. So you can’t pass any old function to@does
, instead the function passed has to take any amount of inputs and process them all in the same way.import pandas as pd from hamilton.function_modifiers import does import internal_package_with_logic def sum_series(**series: pd.Series) -> pd.Series: '''This function takes any number of inputs and sums them all together.''' ... @does(sum_series) def D_XMAS_GC_WEIGHTED_BY_DAY(D_XMAS_GC_WEIGHTED_BY_DAY_1: pd.Series, D_XMAS_GC_WEIGHTED_BY_DAY_2: pd.Series) -> pd.Series: '''Adds D_XMAS_GC_WEIGHTED_BY_DAY_1 and D_XMAS_GC_WEIGHTED_BY_DAY_2''' pass @does(internal_package_with_logic.identity_function) def copy_of_x(x: pd.Series) -> pd.Series: '''Just returns x''' pass
The example here is a function, that all that it does, is sum all the parameters together. So we can annotate it with the
@does
decorator and pass it thesum_series
function. The@does
decorator is currently limited to just allow functions that consist only of one argument, a generic **kwargs.- __init__(replacing_function: Callable, **argument_mapping: str | List[str])#
Constructor for a modifier that replaces the annotated functions functionality with something else. Right now this has a very strict validation requirements to make compliance with the framework easy.
- Parameters:
replacing_function – The function to replace the original function with.
argument_mapping – A mapping of argument name in the replacing function to argument name in the decorating function.