Can you advise if this is reasonable usage of `par...
# hamilton-help
s
Can you advise if this is reasonable usage of
parameterize
and
inject
? This is getting me the result, but the column headers are using the name from the original
source("raw_fee_type")
Is this expected or am I using this incorrectly?
Copy code
@parameterize(**{
    f"is_{exec_type}": {"raw_fee_type": source("raw_fee_type"), "search_exec_type": value(exec_type)}
    for exec_type in ["tas", "block", "efp", "efr", "eoo"]
})
def extract_execution_types(raw_fee_type: pd.Series, search_exec_type: str) -> pd.Series:
    return raw_fee_type.str.contains(search_exec_type, na=False)

@inject(
    all_execution_types=group(*[
        source(f"is_{exec_type}")
        for exec_type in ["tas", "block", "efp", "efr", "eoo"]
        
    ])
)
def execution_types(all_execution_types: List[pd.Series]) -> pd.DataFrame:
    return pd.concat(all_execution_types, axis="columns")
This also repeats the column header from the original
source("raw_fee_type")
Copy code
@resolve( 
    when=ResolveAt.CONFIG_AVAILABLE,
    decorate_with=lambda exec_types: inject(
        all_execution_types=group(
            *[source(f"is_{exec_type}") for exec_type in exec_types]
        )
    ),
)
def execution_types_df(all_execution_types: List[pd.Series]) -> pd.DataFrame:
    return pd.concat(all_execution_types, axis="columns")
e
So this is right, but fairly heavy handed. Re: column-headers, I think this is about being explicit about labeling. It will use the node names to join as columns — you’ll need to set that correctly or rename them. That said, you’re getting to the point where you may want to think a little simpler, or maybe use a higher-level constrcut such as subdag. You’re doing something like this: 1. Have multiple different columns 2. Do a set of operations on them 3. Join them Those could be dataframe operations if you want, or you could run a subdag of operations on each column, then join later
s
Yeah the renaming fixed this approach. May think more about subdag for simplicity.
raw_fee_type.str.contains(search_exec_type, na=False).rename(f"is_{search_exec_type}")
👍 1