Skip to content

multiple return keys for tuple returning functions - #107

Merged
jucordero merged 3 commits into
FixOurFood:ffc_modelfrom
jucordero:multi_out_key
Jul 7, 2026
Merged

multiple return keys for tuple returning functions#107
jucordero merged 3 commits into
FixOurFood:ffc_modelfrom
jucordero:multi_out_key

Conversation

@jucordero

@jucordero jucordero commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR adjusts the behaviour of the pipeline_node decorator to allow functions returning multiple values to store their outputs in multiple keys of the datablock simultaneously

The decorator has two reserved keywords: return_key and return_keys which can only be used to identify the datablock path where results should be stored and cannot be used as part of the function signature.

Checklist

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the pipeline_node decorator to support mapping multi-value (tuple) returns into multiple keys in the pipeline datablock, via a new reserved kwarg return_keys (in addition to return_key).

Changes:

  • Add return_keys as a reserved kwarg name for pipeline_node-decorated functions.
  • Allow passing return_keys to write tuple-return outputs into multiple datablock keys.
  • Keep backward-compatibility intent by falling back to return_key when return_keys is not provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agrifoodpy/pipeline/pipeline.py Outdated
Comment thread agrifoodpy/pipeline/pipeline.py
Comment thread agrifoodpy/pipeline/pipeline.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

agrifoodpy/pipeline/pipeline.py:479

  • The reserved-parameter ValueError message is missing spaces due to implicit string concatenation, which makes the exception hard to read (e.g., ".Please rename..." and "thepipeline_node"). Consider formatting it as a single, well-spaced message (optionally factoring out the reserved params set) for clarity.
        if reserved & set(signature(func).parameters):
            raise ValueError(f"Function {func.__name__} has reserved parameter"
                             f" names {reserved & set(signature(func).parameters)}."
                             "Please rename these parameters to use the"
                             "pipeline_node decorator.")

Comment on lines 426 to +430
input_keys = []

def pipeline_decorator(func):
reserved = {"datablock", "return_key"}

def normalize_return_keys(return_keys):
Comment on lines +506 to +510
return_keys = kwargs.pop("return_keys", None)
return_key = kwargs.pop("return_key", None)

if return_keys is None and return_key is not None:
return_keys = return_key
@jucordero
jucordero merged commit b95eed1 into FixOurFood:ffc_model Jul 7, 2026
4 checks passed
@jucordero
jucordero deleted the multi_out_key branch July 7, 2026 11:33
jucordero added a commit that referenced this pull request Aug 5, 2026
* Changes to food scaling function (#98)

* Changes to food scaling function

* scale above threshold, deprecated drop in tests

* Guard against fallback being defined but origin being not

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* accept scalar conv_arr, fixed conversion, input params in pipeline mode

* unit tests, fixed behaviour of scale parameter

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* added land conversion methods (#100)

* added land conversion methods

* unit tests and docs

* fixed mask and value_array validation in add_category

* added food scaling from land function (#104)

* added food scaling from land function

* Update agrifoodpy/food/model.py

multiple sum

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* Update agrifoodpy/food/model.py

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* Update agrifoodpy/food/model.py

removed land_dimension option

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* Update agrifoodpy/food/model.py

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* added unittest and characters limit

* Update agrifoodpy/food/model.py

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* Update agrifoodpy/food/model.py

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* Update agrifoodpy/food/model.py

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* removed datablock and out_key from food_scaling_from_land

---------

Co-authored-by: Juan Pablo Cordero <34517350+jucordero@users.noreply.github.com>

* FFC project future (#106)

* projecting food balance sheet by population

* Removed stale tests

* fixed docs, guards for zero denoms, consistent docs

* changed labelling for no show parameters in plot functions

* unit tests

* additional scalings and new parser constructor (#105)

* additional scalings and new parser constructor

* updated docs

* multiple return keys for tuple returning functions (#107)

* multiple return keys for tuple returning functions

* return key validation and tuple keys

* fixed docstrings

* options for land plot (#109)

* options for land plot

* updated label values

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: OttaviaTr <74863355+OttaviaTr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants