Skip to content
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

give name of function inside incorrect parameters error #538

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
* Fixed `kedro install` for an Anaconda environment defined in `environment.yml`.
* Fixed backwards compatibility with templates generated with older Kedro versions <0.16.5. No longer need to update `.kedro.yml` to use `kedro lint` and `kedro jupyter notebook convert`.
* Improved documentation.
* Improved error messages for incorrect parameters passed into a node.

## Breaking changes to the API

## Thanks for supporting contributions
[Deepyaman Datta](https://github.com/deepyaman), [Bhavya Merchant](https://github.com/bnmerchant), [Lovkush Agarwal](https://github.com/Lovkush-A)
[Deepyaman Datta](https://github.com/deepyaman), [Bhavya Merchant](https://github.com/bnmerchant), [Lovkush Agarwal](https://github.com/Lovkush-A), [Waylon Walker](https://github.com/waylonwalker)

# Release 0.16.5

Expand Down
44 changes: 28 additions & 16 deletions kedro/pipeline/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,7 @@ def __call__(self, **kwargs) -> Dict[str, Any]:

@property
def _func_name(self):
if hasattr(self._func, "__name__"):
return self._func.__name__

name = repr(self._func)
if "functools.partial" in name:
warn(
"The node producing outputs `{}` is made from a `partial` function. "
"Partial functions do not have a `__name__` attribute: consider using "
"`functools.update_wrapper` for better log messages.".format(
self.outputs
)
)
name = "<partial>"
return name
return _get_readable_func_name(self._func, self.outputs)

@property
def tags(self) -> Set[str]:
Expand Down Expand Up @@ -550,9 +537,11 @@ def _validate_inputs(self, func, inputs):
func_args = inspect.signature(
func, follow_wrapped=False
).parameters.keys()
func_name = _get_readable_func_name(func)

raise TypeError(
"Inputs of function expected {}, but got {}".format(
str(list(func_args)), str(inputs)
"Inputs of '{}' function expected {}, but got {}".format(
func_name, str(list(func_args)), str(inputs)
)
) from exc

Expand Down Expand Up @@ -696,3 +685,26 @@ def _to_list(element: Union[None, str, Iterable[str], Dict[str, str]]) -> List:
if isinstance(element, dict):
return sorted(element.values())
return list(element)


def _get_readable_func_name(
func: Callable, outputs: Union[None, str, List[str], Dict[str, str]] = None
) -> str:
"""Get a readable name of the function provided.

Returns:
str: readable name of the provided callable func.
"""

if hasattr(func, "__name__"):
return func.__name__

name = repr(func)
if "functools.partial" in name and outputs is not None:
warn(
"The node producing outputs `{}` is made from a `partial` function. "
"Partial functions do not have a `__name__` attribute: consider using "
"`functools.update_wrapper` for better log messages.".format(outputs)
)
name = "<partial>"
return name
Empty file added temp1
Empty file.
28 changes: 25 additions & 3 deletions tests/pipeline/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,42 @@ def dummy_func_args(**kwargs):
return dummy_func_args, "A", "B"


lambda_identity = lambda input1: input1 # noqa: disable=E731


def lambda_inconsistent_input_size():
return lambda_identity, ["A", "B"], "C"


partial_identity = partial(identity)


def partial_inconsistent_input_size():
return partial_identity, ["A", "B"], "C"


@pytest.mark.parametrize(
"func, expected",
[
(
inconsistent_input_size,
r"Inputs of function expected \[\'input1\'\], but got \[\'A\', \'B\'\]",
r"Inputs of 'identity' function expected \[\'input1\'\], but got \[\'A\', \'B\'\]",
),
(
inconsistent_input_args,
r"Inputs of function expected \[\'args\'\], but got {\'a\': \'A\'}",
r"Inputs of 'dummy_func_args' function expected \[\'args\'\], but got {\'a\': \'A\'}",
),
(
inconsistent_input_kwargs,
r"Inputs of function expected \[\'kwargs\'\], but got A",
r"Inputs of 'dummy_func_args' function expected \[\'kwargs\'\], but got A",
),
(
lambda_inconsistent_input_size,
r"Inputs of '<lambda>' function expected \[\'input1\'\], but got \[\'A\', \'B\'\]",
),
(
partial_inconsistent_input_size,
r"Inputs of '<partial>' expected \[\'input1\'\], but got \[\'A\', \'B\'\]",
),
],
)
Expand Down