Yijun Tang
11/01/2024, 2:17 PMnew_df . It would be useful to be still able to run the DAG on an older dataset that doesn’t have new_df .Stefan Krawczyk
11/01/2024, 3:34 PMThierry Jean
11/01/2024, 3:48 PMversion 1 that's being used, you made some change to create version 2, and now both versions are in use. Sounds accurate?
I think @config.when can be useful. This allows you to have 2 nodes with the same name but different implementation.
Let's say your version 1 looked like this:
# report.py
import pandas as pd
def monthly_report(sales: pd.DataFrame) -> pd.DataFrame:
return ...
# where you execute code
import report
from hamilton import driver
dr = driver.Builder().with_modules(report).build()
dr.execute(...)
Then, as your project evolve and you want to modify monthly_report() you could use @config.when
# report.py
import pandas as pd
from hamilton.function_modifiers import config
@config.when_not(version="v2")
def monthly_report__v1(sales: pd.DataFrame) -> pd.DataFrame:
return ...
@config.when(version="v2)
def monthy_report__v2(sales: pd.DataFrame, new_df: pd.DataFrame) -> pd.DataFrame:
return ...
Now, when you create your Driver you can pass a config. By passing version="v2" in a dictionary it will use the implementation that has new_df. If the config is empty, it will use the v1 implementation
import report
from hamilton import driver
dr = (
driver.Builder()
.with_modules(report)
.with_config({"version": "v2"})
.build()
)
dr.execute(...)Yijun Tang
11/01/2024, 3:58 PMYijun Tang
11/01/2024, 4:00 PMconfig sounds like a viable option, although is it possible to select all nodes with version <= 2 ? My understanding is .with_config({"version": "v2"}) will only select the red nodes.Stefan Krawczyk
11/01/2024, 4:09 PMStefan Krawczyk
11/01/2024, 4:11 PMStefan Krawczyk
11/01/2024, 4:13 PMYijun Tang
11/01/2024, 4:17 PM@config.when_in(param=["v1", "v2"]) and the red ones with @config.when_in(param=["v2"]) . This way when V3 is introduced, we can add "v3" to both lists.Stefan Krawczyk
11/01/2024, 4:22 PMYijun Tang
11/01/2024, 5:19 PMStefan Krawczyk
11/01/2024, 5:26 PMStefan Krawczyk
11/01/2024, 5:31 PMYijun Tang
11/01/2024, 6:14 PMGracefulErrorAdaptor is looking very promising. I’ll give it a try.