Skip to content

Support NamedTuples for named arguments in parametrizations. #224

@tobiasraabe

Description

@tobiasraabe

Workarounds

typing.NamedTuple or collections.namedtuple can be used to achieve named arguments per iteration of the parametrization.

from pathlib import Path
from typing import NamedTuple


class Task(NamedTuple):
    depends_on: Path
    produces: Path


@pytask.mark.parametrize("depends_on, produces", [
    Task(depends_on="first_dataset.pkl", produces="first_plot.png"),
    Task(depends_on="second_dataset.pkl", produces="second_plot.png"),
])
def task_plot_data(depends_on, produces):
    df = pd.read_pickle(depends_on)
    ax = df.plot()
    plt.savefig(produces)
  • Document example usage in the documentation.
  • Implement a check for whether the arguments of the namedtuple match the signature of the parametrization.

Originally posted by @tobiasraabe in #206 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions