This message was deleted.
# hamilton-help
s
This message was deleted.
z
Copy code
@config.when(cfg_val='0')
@extract_columns('x','y','z')
def concat_v0(
  X_e1: pd.Series, Y_e1: pd.Series, Z_e1: pd.Series, 
  X_e2: pd.Series, Y_e2: pd.Series, Z_e2: pd.Series, 
  X_e3: pd.Series, Y_e3: pd.Series, Z_e3: pd.Series, 
  X_e4: pd.Series, Y_e4: pd.Series, Z_e4: pd.Series) -> pd.DataFrame:

    output = pd.DataFrame({'x': [X_e1, X_e2, X_e3, X_e4],
                           'y': [Y_e1, Y_e2, Y_e3, Y_e4],
                           'z': [Z_e1, Z_e2, Z_e3, Z_e4],}) 

    return output


@config.when(cfg_val='1')
@extract_columns('x','y','z')
def concat_v1(
  X_e1: pd.Series, Y_e1: pd.Series, Z_e1: pd.Series, 
  X_e2: pd.Series, Y_e2: pd.Series, Z_e2: pd.Series, 
  X_e3: pd.Series, Y_e3: pd.Series, Z_e3: pd.Series ) -> pd.DataFrame:
    
    output = pd.DataFrame({'x': [X_e1, X_e2, X_e3],
                           'y': [Y_e1, Y_e2, Y_e3],
                           'z': [Z_e1, Z_e2, Z_e3]})
    return output
s
That should work without issue. The functions don’t need to take the same inputs at all.
Otherwise note, the convention is that there should be two underscores in the function name, i.e. they should be named:
Copy code
@config.when(cfg_val='0')
@extract_columns('x','y','z')
def concact__v0(...):

@config.when(cfg_val='1')
@extract_columns('x','y','z')
def concact__v1(...):
z
thanks, I meant is there a less verbose way of doing the above 😛 for example defining the inputs as **kwargs and telling the driver what kwargs to use depending on the config?
(why the __ convention? does that get stripped from documentation or something?)
s
it gets stripped — so that there’s only one
concat
node in the graph.
thanks, I meant is there a less verbose way of doing the above 😛
for example defining the inputs as **kwargs and telling the driver what kwargs to use depending on the config?
what would that help with? Part of the value of hamilton is it’s pretty explicit what depends on what 🙂 — so a new person coming to own/use the code can know easily.
otherwise you could just make one of the inputs a dict…
👍 1
z
I guess that’d require passing in the whole dataframe instead, and indeed that would obfuscate what the dependency is.
e
OK this is also related to this idea: https://hamilton-opensource.slack.com/archives/C03MANME6G5/p1667381483500809. Starting to look into it and I think you might find some overlap? I concur with @Stefan Krawczyk though -- Hamilton represents a verbosity trade-off -- the code is easier to read/maintain but might be a little wordier.
👀 1