-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dict unpacking with "**params:foo.bar" in node(inputs=)
#2749
Comments
Thanks @m-gris for opening this feature request! We'll discuss about it soon. |
Thanks for considering it ! :) |
I have evidence this could be useful too. But it may requires something more than just unpacking # model_predict/functions.py
def make_prediction(model, a, b, c, d, e):
...
# model_predict_pipeline/nodes.py
def make_prediction_node(model, params: Dict):
make_prediction(
model,
params.get("something", None),
params.get("something", None),
params.get("something", []),
params.get("something", []),
) Noted that here two things are done:
Or maybe 2. is bad and we shouldn't support it because passing a list into function argument is anti-pattern and edit(deepyaman): format code example to make it easier to read |
In short, I think it makes sense to pass a parameters dictionary to a node (i.e. the current supported behavior). While I agree that dict unpacking sounds nice, I wonder how often people would mess up because configuration keys don't match parameter names. Also, how often would the value of supporting this syntax be realized? I feel like it's most beneficial when you have a node (say, On the last example of assigning a default, I tend to agree that you could just use keyword arguments with default. |
I tend to think we shouldn't add arbitrary constrains unless there are good reason. And often users will try to find their way to do it anyway (e.g. Using environment variable for everything).
I think this will be more common if you need to reuse the function, which is something Kedro values. This will work, but as a package it hides all the function signature and it becomes less clear what parameters are available. On the note that you mentioned people may mess up. In that case, I expect it is the same when you use a python function that takes keyword arguments but you passed a wrong keyword. You should get an explicit error and I don't see any problem with that. @m-gris since you created this issue, what's your thoughts on this? |
In general I believe we need this so that modular pipeline reuse can be dynamic |
@datajoely do you have an example? |
See this thread |
Adding more evidence that this would be useful - https://linen-slack.kedro.org/t/13902185/if-kedro-supports-unpacking-parameters-dictionary-would-it-c#fe7ba273-2708-4764-8473-920b0636e78f Markus Sagen and marcccin is in favor of this too |
Imho, unpacking at the pipeline compilation level would be also beneficial from the perspective of pipeline validation. If I understand correctly -let's say we have
def node(data_input, a, b, c):
# use c
pass Using the "unpacking" whereas for node def node(data_input, params: dict):
# use params["c"]
pass with |
good point! |
Hi |
@m-gris Would you be able to open a PR on this? We have a brief discussion today and we think it would be a useful feature to add. It's not our priority immediately, but we are happy to accept PR as this is something useful to the community. |
@noklam |
@m-gris Amazing! That's totally fine and looking forward to the PR 🚀 |
Just adding additional info where this could be useful. This isn't on the **kwargs unpacking but the *args unpacking: https://linen-slack.kedro.org/t/9703505/hey-all-simple-question-is-it-possible-to-pass-both-position |
@inigohidalgo good point, I have raised the same issue in #2924 (comment) More broadly I think we should look at this as how different a node is versus a Python function. I also not sure how hard is it to implement a non breaking change. |
When defining a node, it would be really nice and convenient if the params dictionary could be unpacked with something like:
This would not only make the node definition more concise than
But it would also result in a more dynamic and flexible node definition, "immune" to changes in the function's signature.
(in which case all that would require an update would be the params file, as opposed to both the node def. and the params file in the other case)
I hope that this request / suggestion does not go against Kedro philosophy :)
Thx & regards
M.
The text was updated successfully, but these errors were encountered: