Seth Stokes
10/17/2024, 7:05 PMraw_data and split it using groupby(key="exchange") .
Then have a module that can be applied for each exchange.
I'd like to be able to dr.execute() each exchange independently or all at once.
Is this reasonable?
from hamilton.function_modifiers import subdag, parameterized_subdag
def raw_data() -> pd.DataFrame:
return ...
@extract_fields({
f"{xch}_data": pd.DataFrame for xch in ["xch1","xch2"]
})
def _split_exchanges(raw_data: pd.DataFrame) -> pd.DataFrame:
return {
xch: df for xch, df in raw_data.groupby(key="exchange")
}
# how can i apply these modules to these extracted fields
# calculate_rates_xch1.py
# calculate_rates_xch2.py
calculate_rates_xch1 = ...
calculate_rates_xch2 = ...
@subdag(calculate_rates_xch1, external_inputs=[f"{xch1}_data"])
def rates_xch1(calculated_rates: pd.DataFrame) -> pd.DataFrame:
return calculated_rates
@subdag(calculate_rates_xch2, external_inputs=[f"{xch2}_data"])
def rates_xch2(calculated_rates: pd.DataFrame) -> pd.DataFrame:
return calculated_rates
def rates_all(rates_xch1: pd.DataFrame, rates_xch2: pd.DataFrame) -> pd.DataFrame:
return pd.concat([*locals().values()])Stefan Krawczyk
10/17/2024, 8:20 PMSeth Stokes
10/17/2024, 8:25 PMStefan Krawczyk
10/17/2024, 8:27 PMrates_xch2 or you can ask for rates_all (though I think the input parameters should be rates_xch1 & rates_xch2?)Seth Stokes
10/17/2024, 8:28 PMSeth Stokes
10/17/2024, 8:29 PMSeth Stokes
10/17/2024, 8:29 PMStefan Krawczyk
10/17/2024, 8:46 PM