-
The |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 11 replies
-
@gravesee can you clarify by providing some pseudo code and what you would expect to happen? |
Beta Was this translation helpful? Give feedback.
-
[edit] We have a new decorator We have two decorators that you can use together:
|
Beta Was this translation helpful? Give feedback.
-
@skrawcz thank you. I think my users will want more flexibility. I have provided more detail below. I know beggars can't be choosers and hamilton solves a real problem for my team! For data governance we have a lot of metadata for out features. Currently it is either in docstrings or in separate files. I really like how I can keep everything together in hamilton and get to query the metadata. from hamilton.function_modifiers import parameterize_sources
import pandas as pd
# current code looks like this
@parameterize_sources(
**{"public_usage": {"invar": "outvar1"}, "private_usage": {"invar": "outvar2"}}
)
def outvar_logic(invar: pd.Series) -> pd.Series:
# logic goes here
return invar
# without parameterize_sources I would have to repeat myself
@tag(usage='public')
def outvar1(...) -> pd.Series:
...
@tag(usage='private')
def outvar1(...) -> pd.Series:
...
# is there a way to add tags to nodes that are generated? Any programmatic means?
outvar_logic.output_nodes['outvar1'].tags = {
'usage': 'public'
}
outvar_logic.output_nodes['outvar2'].tags = {
'usage': 'private'
} |
Beta Was this translation helpful? Give feedback.
-
Adding to this -- we're looking at ways to make querying nodes easy. If this would be helpful, feel free to leave feedback! #159 |
Beta Was this translation helpful? Give feedback.
-
So yeah, as @skrawcz said applying different tags to different nodes produced by the same function is not currently feasible. How's this for a possible change though... The nice thing is that this just generally works for any decorators that output multiple nodes... @tag_outputs(
public_usage={'usage' : 'public'},
private_usage = {'usage' : 'private'})
@parameterize_sources(
**{"public_usage": {"invar": "outvar1"}, "private_usage": {"invar": "outvar2"}}
)
def outvar_logic(invar: pd.Series) -> pd.Series:
# logic goes here
return invar Thoughts on this API? Its a little verbose but quite flexible -- works for extract, etc... |
Beta Was this translation helpful? Give feedback.
[edit] We have a new decorator
@tag_outputs
since1.12.0
that solves this exact case[/edit]We have two decorators that you can use together:
@tag
@tag_outputs
@tag
Tags all the outputs with the same key and value.
@tag_outputs
Tags individual outputs with specific keys and values.
In the example below, we see that
@tag
is used to set a value for all outputs, while@tag_outputs
is only used to add a tag toavg_2wk_spend
: