Node Parameters¶
Up to this point we've dealt with defining nodes and composing them together into pipelines. One issue is that all of the logic is static, the pipelines are unable to changed by external sources. Node Parameters are the solution to this- they comprise named arguments of a node that are defined at the point where the pipeline is run.
Definition¶
In [1]:
Copied!
import pandas as pd
from flypipe.node import node
@node(type="pandas")
def t1(param1):
print(f"param1: `{param1}`")
return pd.DataFrame()
@node(
type="pandas",
dependencies=[t1]
)
def t2(t1):
return t1
df = t2.run(parameters={t1: {"param1": "hello"}})
import pandas as pd
from flypipe.node import node
@node(type="pandas")
def t1(param1):
print(f"param1: `{param1}`")
return pd.DataFrame()
@node(
type="pandas",
dependencies=[t1]
)
def t2(t1):
return t1
df = t2.run(parameters={t1: {"param1": "hello"}})
param1: `hello`
Note just like any python function argument we can give a default value to use if no value is provided at runtime.
In [2]:
Copied!
import pandas as pd
from flypipe.node import node
@node(type="pandas")
def t1(param1=None):
print(f"param1: `{param1}`")
return pd.DataFrame()
df = t1()
import pandas as pd
from flypipe.node import node
@node(type="pandas")
def t1(param1=None):
print(f"param1: `{param1}`")
return pd.DataFrame()
df = t1()
param1: `None`
Parameters and node functions¶
Parameters can also be used with node functions, together you have more flexibility on dynamically changing not only node behaviours but also graph compositions
In [3]:
Copied!
from flypipe import node_function
@node_function()
def t1_func(node_selector="t1"):
@node(type="pandas")
def t1():
return pd.DataFrame()
if node_selector == "t1":
return t1
@node(
type="pandas",
dependencies=[t1]
)
def t2():
return pd.DataFrame()
return t2, t1
displayHTML(t1_func.html())
from flypipe import node_function
@node_function()
def t1_func(node_selector="t1"):
@node(type="pandas")
def t1():
return pd.DataFrame()
if node_selector == "t1":
return t1
@node(
type="pandas",
dependencies=[t1]
)
def t2():
return pd.DataFrame()
return t2, t1
displayHTML(t1_func.html())
Out[3]: