Skip to content

Remove @pytask.mark.parametrize. #391

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

Merged
merged 4 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions docs/source/_static/images/markers.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions docs/source/_static/md/markers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ $ pytask markers
│ │ tutorial for more information: │
│ │ <a href="https://bit.ly/3JlxylS">https://bit.ly/3JlxylS</a>. │
│ │ │
│ pytask.mark.parametrize │ The marker for pytest&#x27;s way of │
│ │ repeating tasks which is explained in │
│ │ this tutorial: <a href="https://bit.ly/3uqZqkk">https://bit.ly/3uqZqkk</a>. │
│ │ │
│ pytask.mark.persist │ Prevent execution of a task if all │
│ │ products exist and even ifsomething has │
│ │ changed (dependencies, source file, │
Expand Down
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and

- {pull}`323` remove Python 3.7 support and use a new Github action to provide mamba.
- {pull}`387` replaces pony with sqlalchemy.
- {pull}`391` removes `@pytask.mark.parametrize`.

## 0.3.2 - 2023-06-07

Expand Down
1 change: 0 additions & 1 deletion docs/source/how_to_guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ maxdepth: 1
migrating_from_scripts_to_pytask
invoking_pytask_extended
capture_warnings
repeating_tasks_with_different_inputs_the_pytest_way
how_to_influence_build_order
how_to_write_a_plugin
```
Expand Down

This file was deleted.

29 changes: 0 additions & 29 deletions docs/source/reference_guides/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,6 @@ by the host or by plugins. The following marks are available by default.
:func:`_pytask.hookspecs.pytask_collect_node` entry-point.
```

```{eval-rst}
.. function:: pytask.mark.parametrize(arg_names, arg_values, *, ids)

Parametrize a task function.

Parametrizing a task allows to execute the same task with different arguments.

:type arg_names: str | list[str] | tuple[str, ...]
:param arg_names:
The names of the arguments which can either be given as a comma-separated
string, a tuple of strings, or a list of strings.
:type arg_values: Iterable[Sequence[Any] | Any]
:param arg_values:
The values which correspond to names in ``arg_names``. For one argument, it is a
single iterable. For multiple argument names it is an iterable of iterables.
:type ids: None | (Iterable[None | str | float | int | bool] | Callable[..., Any])
:param ids:
This argument can either be a list with ids or a function which is called with
every value passed to the parametrized function.

If you pass an iterable with ids, make sure to only use :obj:`bool`,
:obj:`float`, :obj:`int`, or :obj:`str` as values which are used to create task
ids like ``"task_dummpy.py::task_dummy[first_task_id]"``.

If you pass a function, the function receives each value of the parametrization
and may return a boolean, number, string or None. For the latter, the
auto-generated value is used.
```

```{eval-rst}
.. function:: pytask.mark.persist()

Expand Down
15 changes: 0 additions & 15 deletions docs/source/reference_guides/hookspecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,6 @@ The following hooks traverse directories and collect tasks from files.

```

## Parametrization

The hooks to parametrize a task are called during the collection when a function is
collected. Then, the function is duplicated according to the parametrization and the
duplicates are collected with {func}`pytask_collect_task`.

```{eval-rst}
.. autofunction:: pytask_parametrize_task
```

```{eval-rst}
.. autofunction:: pytask_parametrize_kwarg_to_marker

```

## Resolving Dependencies

The following hooks are designed to build a DAG from tasks and dependencies and check
Expand Down
45 changes: 33 additions & 12 deletions docs/source/tutorials/repeating_tasks_with_different_inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

Do you want to repeat a task over a range of inputs? Loop over your task function!

:::{important}
Before v0.2.0, pytask supported only one approach to repeat tasks. It is also called
parametrizations, and similarly to pytest, it uses a
{func}`@pytask.mark.parametrize <pytask.mark.parametrize>` decorator. If you want to
know more about it, you can find it
{doc}`here <../how_to_guides/repeating_tasks_with_different_inputs_the_pytest_way>`.

Here you find the new and preferred approach.
:::

## An example

We reuse the task from the previous {doc}`tutorial <write_a_task>`, which generates
Expand Down Expand Up @@ -71,9 +61,40 @@ and the name of the task function. Here is an example.
```

This behavior would produce duplicate ids for parametrized tasks. By default,
auto-generated ids are used which are explained {ref}`here <auto-generated-ids>`.
auto-generated ids are used.

(auto-generated-ids)=

### Auto-generated ids

pytask construct ids by extending the task name with representations of the values used
for each iteration. Booleans, floats, integers, and strings enter the task id directly.
For example, a task function that receives four arguments, `True`, `1.0`, `2`, and
`"hello"`, one of each dtype, has the following id.

```
task_data_preparation.py::task_create_random_data[True-1.0-2-hello]
```

Arguments with other dtypes cannot be converted to strings and, thus, are replaced with
a combination of the argument name and the iteration counter.

More powerful are user-defined ids.
For example, the following function is parametrized with tuples.

```python
for i in [(0,), (1,)]:

@pytask.mark.task
def task_create_random_data(i=i):
pass
```

Since the tuples are not converted to strings, the ids of the two tasks are

```
task_data_preparation.py::task_create_random_data[i0]
task_data_preparation.py::task_create_random_data[i1]
```

(ids)=

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ extend-ignore = [
"SLF001", # access private members.
"S603",
"S607",
# Temporary
"TD002",
"TD003",
]


Expand Down
2 changes: 0 additions & 2 deletions src/_pytask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def pytask_add_hooks(pm: pluggy.PluginManager) -> None:
from _pytask import mark
from _pytask import nodes
from _pytask import parameters
from _pytask import parametrize
from _pytask import persist
from _pytask import profile
from _pytask import dag
Expand All @@ -89,7 +88,6 @@ def pytask_add_hooks(pm: pluggy.PluginManager) -> None:
pm.register(mark)
pm.register(nodes)
pm.register(parameters)
pm.register(parametrize)
pm.register(persist)
pm.register(profile)
pm.register(dag)
Expand Down
Loading