cuddly-jelly-27016
02/26/2025, 5:09 AMimport importlib
import pandas as pd
from hamilton import driver
logging.basicConfig(stream=sys.stdout)
initial_columns = { # load from actuals or wherever -- this is our initial data we use as input.
# Note: these do not have to be all series, they could be scalar inputs.
'signups': pd.Series([1, 10, 50, 100, 200, 400]),
'spend': pd.Series([10, 10, 20, 40, 40, 50]),
}
# we need to tell hamilton where to load function definitions from
module_name = 'my_functions'
module = importlib.import_module(module_name)
dr = driver.Driver(initial_columns, module) # can pass in multiple modules
# we need to specify what we want in the final dataframe.
output_columns = [
'spend',
'signups',
'avg_3wk_spend',
'spend_per_signup',
]
# let's create the dataframe!
# if you only did `pip install sf-hamilton` earlier:
df = dr.execute(output_columns)
# else if you did `pip install sf-hamilton[visualization]` earlier:
# dr.visualize_execution(output_columns, './my-dag.dot', {})
print(df)
See https://github.com/outerbounds/hamilton-metaflow for an example of Hamilton + metaflow -- hamilton helps with the feature engineering step. So conceptually we'd try to integration simpler than just creating a task in flyte, with a plugin instead...
flyteorg/flytecuddly-jelly-27016
02/26/2025, 5:09 AM