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

Add docs for *args usage for node definition #4019

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/source/nodes_and_pipelines/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
| `None` | No input | `def f()` | `f()` |
| `'a'` | Single input | `def f(arg1)` | `f(a)` |
| `['a', 'b']` | Multiple inputs | `def f(arg1, arg2)` | `f(a, b)` |
| `['a', 'b', 'c']` | Variable inputs | `def f(arg1, *args)`. | `f(arg1, arg2, arg3)` |
| `dict(arg1='x', arg2='y')` | Keyword inputs | `def f(arg1, arg2)` | `f(arg1=x, arg2=y)` |

### Syntax for output variables
Expand All @@ -87,6 +88,9 @@

Any combinations of the above are possible, except nodes of the form `node(f, None, None)` (at least a single input or output must be provided).

## `*args` node functions
It is common to have functions that take an arbitrary number of inputs, like a function that combines multiple dataframes. You can use the `*args` argument in the node function, while simply declaring the names of the datasets in the node's inputs.

Check warning on line 92 in docs/source/nodes_and_pipelines/nodes.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/source/nodes_and_pipelines/nodes.md#L92

[Kedro.toowordy] 'multiple' is too wordy
Raw output
{"message": "[Kedro.toowordy] 'multiple' is too wordy", "location": {"path": "docs/source/nodes_and_pipelines/nodes.md", "range": {"start": {"line": 92, "column": 103}}}, "severity": "WARNING"}

Check warning on line 92 in docs/source/nodes_and_pipelines/nodes.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/source/nodes_and_pipelines/nodes.md#L92

[Kedro.Spellings] Did you really mean 'dataframes'?
Raw output
{"message": "[Kedro.Spellings] Did you really mean 'dataframes'?", "location": {"path": "docs/source/nodes_and_pipelines/nodes.md", "range": {"start": {"line": 92, "column": 112}}}, "severity": "WARNING"}

Check warning on line 92 in docs/source/nodes_and_pipelines/nodes.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/source/nodes_and_pipelines/nodes.md#L92

[Kedro.weaselwords] 'simply' is a weasel word!
Raw output
{"message": "[Kedro.weaselwords] 'simply' is a weasel word!", "location": {"path": "docs/source/nodes_and_pipelines/nodes.md", "range": {"start": {"line": 92, "column": 185}}}, "severity": "WARNING"}

Check warning on line 92 in docs/source/nodes_and_pipelines/nodes.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/source/nodes_and_pipelines/nodes.md#L92

[Kedro.words] Use '' instead of 'simply'.
Raw output
{"message": "[Kedro.words] Use '' instead of 'simply'.", "location": {"path": "docs/source/nodes_and_pipelines/nodes.md", "range": {"start": {"line": 92, "column": 185}}}, "severity": "WARNING"}

## `**kwargs`-only node functions

Sometimes, when creating reporting nodes for instance, you need to know the names of the datasets that your node receives, but you might not have this information in advance. This can be solved by defining a `**kwargs`-only function:
Expand Down