Slackbot
10/25/2022, 8:24 PMStefan Krawczyk
10/25/2022, 8:28 PMStefan Krawczyk
10/25/2022, 9:13 PMStefan Krawczyk
10/25/2022, 9:15 PMStefan Krawczyk
10/25/2022, 9:17 PM@config.when(mean_type='A')
def moving_average__A(input1: ... ) -> ...:
# logic for A version
...
@config.when(mean_type='B')
def moving_average__B(input1: ... ) -> ...:
# logic for B version
...
That will switch out and run different logic ā you can hard code values here if you like and itāll be close to the transforms.Stefan Krawczyk
10/25/2022, 9:20 PM@config.when(mean_type='special')
def moving_average__special(custom_object: ITS_TYPE, input1: ...) -> ...:
# logic to use the custom object... e.g.
return custom_object.compute(input1)
Stefan Krawczyk
10/25/2022, 9:20 PMStefan Krawczyk
10/25/2022, 9:25 PMIād like to keep track of all of these parameters in some python (data)class/attrs object.you have options ā depends on how you want to manage that code. i.e. with the transforms themselves (as alluded to above), with the driver code, or outside of hamilton code entirely.
Stefan Krawczyk
10/25/2022, 9:31 PMdef moving_average(config_required: dict) -> ...:
# use a dict of things to parameterize this function's logic
...
and the driver code would be
# for first DF
config = {
'config_required': {...} # or load from some other place
'input': df_1
}
dr = driver.Driver(config, modules)
df = dr.execute([...])
# for second DF
config = {
'config_required': {...} # or load from some other place
'input': df_2
}
dr = driver.Driver(config, modules)
df = dr.execute([...])
Stefan Krawczyk
10/25/2022, 9:32 PMZouhair Mahboubi
10/25/2022, 10:32 PMconfig_required
in this example) need to be json serialazable (dicts/etc.) or can they be any python object (e.g. a callback, a class, etc.)
2. can these other parameters/objects be in inputs vs in config?
a. and whatās the difference between putting inputs in the config vs passing it to driver.execute as shown for example here ?Elijah Ben Izzy
10/25/2022, 11:15 PMconfig.when
). So it can actually shape the DAG. Inputs (as well as config) are passed in during runtime ā so you can actually declare a dependency on an it. If itās not passed in, execution will error out!Elijah Ben Izzy
10/25/2022, 11:18 PM# can be run with bar supplied in inputs *or* config
def foo(bar: int) -> int:
...
# bar has to be supplied in "config"
@config.when(bar=1)
def foo__1() -> int:
...
Note thereās the notion of overrides (not config
or inputs
but a third, more mysterious thing š) that enables you to short-circuit node execution and replace a node. But I digressā¦Zouhair Mahboubi
10/26/2022, 1:35 AMElijah Ben Izzy
10/26/2022, 1:36 AM