How to pass a literal value to a kedro node?

Question:

I’ve got a function

def do_something(input_data, column: int):

    # Do something with one column of the data

Now I need to create a kedro node, but I can’t do node(do_something, ["input_data", 1], "output"). How can I put the constant value (1) into the node?

Asked By: Anton Kirilenko

||

Answers:

One approach would be to pass the data via params. Add column_number: 1 to the parameters.yaml file, and then your node definition would look like node(do_something ["input_data", "params:column_number"], "output").

If you need to reuse the same function in many nodes, changing the column, then it will not work easily. Instead you can use partial, something like node(partial(do_something, column=1), "input_data", "output"])

Answered By: Anton Kirilenko
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.