Hello, I'm looking into using tags into my work f...
# hamilton-help
d
Hello, I'm looking into using tags into my work flows. I use parameterize quite a lot, and I was wondering if there was a way of combining them (with different tags for the different nodes). For example, I'd like to do something like this:
Copy code
COUNTRY_CODES = ['BE', 'NL', 'FR', 'DE', ...]
load_parameterization = { f"{cc.lower()}_load": dict(cc=value(cc)) for cc in COUNTRY_CODES }

@parameterize(**load_parameterization) 
def country_load(cc: str) -> pd.Series: 
    # Some specific way of getting the countries load
    return get_load(cc)
without resorting to this:
Copy code
@tag(cc='BE')
def be_load():
return get_load('BE')

@tag(cc='NL')
def nl_load():
return get_load('NL')

...
Is something like this already possible? I appreciate the help. Cheers Dries
s
@Dries Hugaerts thanks for the Q. IIUC you want: • add tags to nodes • be able to use that within the graph For (1), I think you want to look at resolve. That is the way to dynamically add decorators to a function before the graph is built. For (2), that isn't possible right now. Tags are consumable given a hamilton driver, and not within a running graph. Otherwise
COUNTRY_CODES = ['BE', 'NL', 'FR', 'DE', ...]
load_parameterization = { f"{cc.lower()}_load": dict(cc=value(cc)) for cc in COUNTRY_CODES }
@parameterize(**load_parameterization)
def country_load(cc: str) -> pd.Series:
# Some specific way of getting the countries load
return get_load(cc)
seems like it should work? What are you encountering here?
d
Thanks for the response. To clarify, I don't need to use the tags inside the graph's execution. I need the tags to exist as metadata on each uniquely generated node so that I can query them later using the Hamilton Driver for filtering or integration with other tools. —> Is there a way to apply a unique tag, like @tag(cc='BE'), to the be_load node when it's generated by @parameterize?
šŸ‘ 1
s
@Dries Hugaerts I'm not sure if this will work (haven't tested with @parameterize) -- but you could try https://hamilton.apache.org/reference/decorators/tag/#hamilton.function_modifiers.tag_outputs ? Otherwise please create an issue for this -- this seems like a reasonable request.
d
Hey, yes that worked perfectly šŸ‘Œ. Thanks for the suggestion
šŸ™Œ 1