Slackbot
06/16/2023, 8:12 AMStefan Krawczyk
06/16/2023, 2:53 PMit seems they are more for cases when you want to run a node N times for each parameter specificationClose. You can think of
@parameterize*
decorators as a function that “creates a bunch of other functions”. E.g. you have a fixed list of parameters and you want to create a function per “parameter”, where a “parameter” can be values, or other functions/nodes you want to depend on. For simple values, rather than writing:
def spend_lag_1_week(spend: pd.Series) -> pd.Series:
return spend.shift(1)
def spend_lag_2_week(spend: pd.Series) -> pd.Series:
return spend.shift(2)
...
you can write
MAPPING = {
(f'spend_lag_{v}_week', f'Spend lag {v}'): v for v in [1, 2, 3, 4, ..., n]
}
@parameterize_values(parameter="shift_value", assigned_output=MAPPING)
def spend_lag_creator(shift_value: int, spend: pd.Series) -> pd.Series
return spend.shift(shift_value)
I was looking to run a node only once but with the “parameter” specified at runtime.Yep you can do that easily. You just need to adjust your example:
def c(a: pd.Series, b: pd.Series, param1: int, param2: int) -> pd.Series:
# return a * 3 + b * 2
return a * param1 + b * param2
Then at run time, you’d just pass in:
"param1":3, "param2":2
as inputs to .execute()
dr = driver.Driver(config, module1, ...)
df = dr.execute(["output1", ...], inputs={"param1":3, "param2":2})
Stefan Krawczyk
06/16/2023, 2:54 PMishan
06/16/2023, 6:43 PM