https://kedro.org/ logo
#questions
Title
# questions
t

Trevor

08/02/2023, 5:35 PM
Sorry, thought I was putting those previous messages in a single thread. Fixed New question, new thread: Is there a way to set a parameter in a node? If my first node calls a function
date()
that simply gets the datetime date, can I assign that date to a parameter?
n

Nok Lam Chan

08/02/2023, 11:08 PM
You will probably want to set it as parameters instead of changing your parameters in a pipeline - this makes your pipeline very hard to debug. As your previous question is asking about how to output the parameters, imagine if your parameters later actually get assigned a different value.
The easiest way to do so is probably to register a custom resolver with
OmegaConfigLoader
(itโ€™s merge but not released yet) Essentially you will register a function
my_date
in your OmegaConfigLoader And then in your parameter.yml you can reference it with
Copy code
my_date : ${my_date}
t

Trevor

08/03/2023, 12:41 AM
Oh that is very fun, I'll have to try that out. Thanks!
a

Ankita Katiyar

08/03/2023, 1:19 PM
@Nok Lam Chan is right - after the next release (or if you use the
main
branch of the source code), you would be able to set custom resolvers through
CONFIG_LOADER_ARGS
in your
settings.py
like this :
Copy code
def mydate():
    return whatever

CONFIG_LOADER_ARGS = {
    "custom_resolvers": {
        "date_resolver": lambda: mydate(),
    }
}
And then in your
parameters.yml
Copy code
my_date: "${date_resolver:}"
--- Right now you can also do in your
settings.py
Copy code
def mydate():
    return whatever

from omegaconf import OmegaConf
if not OmegaConf.has_resolver("date_resolver"):
    OmegaConf.register_new_resolver("date_resolver, lamda: mydate())
๐Ÿ‘ 1
๐Ÿ‘๐Ÿผ 1