Massinissa Saïdi
01/30/2023, 5:34 PM--params
in code with KedroSession
?
I have something like that
def get_session() -> Optional[MyKedroSession]:
bootstrap_project(Path.cwd())
try:
session = MyKedroSession.create()
except RuntimeError as exc:
<http://_log.info|_log.info>(f"Session doesn't exist, creating a new one. Raise: {exc}")
package_name = str(Path(__file__).resolve().parent.name)
session = MyKedroSession.create(package_name)
return session
def get_parameters():
context = get_session().load_context()
return context.params
But get_parameters
gives the parameters set in yaml and not the updated with --params
? thx !datajoely
01/30/2023, 5:34 PMMassinissa Saïdi
01/30/2023, 5:35 PMFlorianGD
01/31/2023, 10:16 AM--params
but with KedroSession
, you can use extra_params
:
with KedroSession.create(extra_params={"my_param": 1}) as session:
parameters = session.load_context().params
And here the my_param
value will be updatedMassinissa Saïdi
01/31/2023, 10:20 AMget_parameters
function (for example). The function written above retrieves the parameters displayed in parameters.yml
. However, when using --params
the parameters file does not change so I can't get the parameters updated with --params
.FlorianGD
01/31/2023, 10:24 AMget_parameters
function? Because, the way I gave you above is the equivalent of passing --params
, but programaticaly. If you want to use it inside of a pipeline, then don't write this function, and pass the parameter name in the node directly, and let Kedro handle that for youMassinissa Saïdi
01/31/2023, 10:28 AMFlorianGD
01/31/2023, 10:33 AMMassinissa Saïdi
01/31/2023, 10:37 AMdef create_pipeline(**kwargs) -> Pipeline:
pipelines = [
node(...),
node(...),
]
if param1 == "value":
pipelines += [node(...)]
return pipeline(pipelines)
FlorianGD
01/31/2023, 10:38 AMMassinissa Saïdi
01/31/2023, 10:39 AM