Can `@mutate` and `@inject` work together? ```def...
# hamilton-help
s
Can
@mutate
and
@inject
work together?
Copy code
def _to_int(srs: pd.Series) -> pd.Series:
    return srs.str.extract("(\d+)", expand=False).fillna(0).astype(int)

@mutate(buy_qty, sell_qty, _to_int)
@inject(buy_qty=source("Bought Quantity"), sell_qty=source("Sold Quantity"))
def QUANTITY(buy_qty: pd.Series, sell_qty: pd.Series) -> pd.Series:
    """TODO - ...

    raw data:
    
    | Index | Bought Quantity | Sold Quantity |
    |:-----:|:---------------:|:-------------:|
    |   0   |                 |       5       |
    |   1   |        2        |               |
    |   2   |                 |       6       |
    |   3   |        9        |               |
    |   4   |        6        |               |
    """
    return buy_qty.fillna(0) + sell_qty.fillna(0)
s
no, they should not (or at least we hadn’t designed for that I don’t think).
why do you want to use inject here? it doesn’t seem necessary
mutate has to operate on some prior defined hamilton functions, in this case “buy_qty”, and “sell_qty”. See docs on usage here.
t
I believe Seth uses
source()
and
@inject
in order to rename columns. This way
"Bought Quantity"
(the raw column name) is available node name. For the above pattern to work, you would just need a renaming step to have
Bought Quantity
and
buy_qty
be available names
s
Yeah that was it, thank you sir