From fbc6570366aa94b5836109db9d08e3de26af04ab Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 14 Mar 2024 12:07:44 +0000 Subject: [PATCH 1/4] Added extra inputs/outputs variables validation at the Node level Signed-off-by: Elena Khaustova --- kedro/pipeline/node.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/kedro/pipeline/node.py b/kedro/pipeline/node.py index 32baaf8e35..ba0d43cddf 100644 --- a/kedro/pipeline/node.py +++ b/kedro/pipeline/node.py @@ -42,7 +42,7 @@ def __init__( # noqa: PLR0913 function. When dict[str, str] is provided, variable names will be mapped to function argument names. outputs: The name or the list of the names of variables used - as outputs to the function. The number of names should match + as outputs of the function. The number of names should match the number of outputs returned by the provided function. When dict[str, str] is provided, variable names will be mapped to the named outputs the function returns. @@ -67,7 +67,6 @@ def __init__( # noqa: PLR0913 and/or fullstops. """ - if not callable(func): raise ValueError( _node_error_message( @@ -83,6 +82,16 @@ def __init__( # noqa: PLR0913 ) ) + for _input in _to_list(inputs): + if not isinstance(_input, str): + raise ValueError( + _node_error_message( + f"names of variables used as inputs to the function " + f"must be of 'String' type, but {_input} from {inputs} " + f"is '{type(_input)}'." + ) + ) + if outputs and not isinstance(outputs, (list, dict, str)): raise ValueError( _node_error_message( @@ -91,6 +100,16 @@ def __init__( # noqa: PLR0913 ) ) + for _output in _to_list(outputs): + if not isinstance(_output, str): + raise ValueError( + _node_error_message( + f"names of variables used as outputs of the function " + f"must be of 'String' type, but {_output} from {outputs} " + f"is '{type(_output)}'." + ) + ) + if not inputs and not outputs: raise ValueError( _node_error_message("it must have some 'inputs' or 'outputs'.") From c7a24875c76acf731e41fa7e3a0cb4fc9bcfdf05 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 14 Mar 2024 14:59:49 +0000 Subject: [PATCH 2/4] Fixing potential typo Signed-off-by: Elena Khaustova --- tests/ipython/conftest.py | 2 +- tests/pipeline/test_node.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/ipython/conftest.py b/tests/ipython/conftest.py index edc7dbc9e8..f263602741 100644 --- a/tests/ipython/conftest.py +++ b/tests/ipython/conftest.py @@ -111,7 +111,7 @@ def dummy_node_empty_input(): return node( func=dummy_function, inputs=["", ""], - outputs=[None], + outputs=None, name="dummy_node_empty_input", ) diff --git a/tests/pipeline/test_node.py b/tests/pipeline/test_node.py index ae68dff87e..3dcf3db790 100644 --- a/tests/pipeline/test_node.py +++ b/tests/pipeline/test_node.py @@ -252,6 +252,14 @@ def duplicate_output_list_node(): return identity, "A", ["A", "A"] +def bad_input_variable_name(): + return lambda x: None, {"a": 1, "b": "B"}, {"a": "A", "b": "B"} + + +def bad_output_variable_name(): + return lambda x: None, {"a": "A", "b": "B"}, {"a": "A", "b": 2} + + @pytest.mark.parametrize( "func, expected", [ @@ -275,6 +283,11 @@ def duplicate_output_list_node(): r"\(\[A\]\) -> \[A;A\] due to " r"duplicate output\(s\) {\'A\'}.", ), + (bad_input_variable_name, "names of variables used as inputs to the function "), + ( + bad_output_variable_name, + "names of variables used as outputs of the function ", + ), ], ) def test_bad_node(func, expected): From 7c8ccaa98c438ca5545ae31ff8486ea0cf09eb87 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 14 Mar 2024 15:22:29 +0000 Subject: [PATCH 3/4] Added release note Signed-off-by: Elena Khaustova --- RELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.md b/RELEASE.md index c534720754..b1b158895f 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,6 +1,7 @@ # Upcoming Release 0.19.4 ## Major features and improvements +* Improved error message when passing wrong value to node. * Cookiecutter errors are shown in short format without the `--verbose` flag. * Kedro commands now work from any subdirectory within a Kedro project. * Kedro CLI now provides a better error message when project commands are run outside of a project i.e. `kedro run` From 15b2c728cae33ba4dfdb3e8f469401b76fb7249c Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 14 Mar 2024 16:03:38 +0000 Subject: [PATCH 4/4] Retrigger the CI Signed-off-by: Elena Khaustova --- RELEASE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index b1b158895f..8f28362c26 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -4,7 +4,7 @@ * Improved error message when passing wrong value to node. * Cookiecutter errors are shown in short format without the `--verbose` flag. * Kedro commands now work from any subdirectory within a Kedro project. -* Kedro CLI now provides a better error message when project commands are run outside of a project i.e. `kedro run` +* Kedro CLI now provides a better error message when project commands are run outside of a project i.e. `kedro run`. ## Bug fixes and other changes * Updated `kedro pipeline create` and `kedro pipeline delete` to read the base environment from the project settings.