Skip to content

Commit a99e54a

Browse files
authored
Remove @pytask.mark.parametrize. (#391)
1 parent 1ec428b commit a99e54a

23 files changed

+171
-1369
lines changed

docs/source/_static/images/markers.svg

Lines changed: 0 additions & 3 deletions
Loading

docs/source/_static/md/markers.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ $ pytask markers
1010
│ │ tutorial for more information: │
1111
│ │ <a href="https://bit.ly/3JlxylS">https://bit.ly/3JlxylS</a>. │
1212
│ │ │
13-
│ pytask.mark.parametrize │ The marker for pytest&#x27;s way of │
14-
│ │ repeating tasks which is explained in │
15-
│ │ this tutorial: <a href="https://bit.ly/3uqZqkk">https://bit.ly/3uqZqkk</a>. │
16-
│ │ │
1713
│ pytask.mark.persist │ Prevent execution of a task if all │
1814
│ │ products exist and even ifsomething has │
1915
│ │ changed (dependencies, source file, │

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
99

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

1314
## 0.3.2 - 2023-06-07
1415

docs/source/how_to_guides/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ maxdepth: 1
1414
migrating_from_scripts_to_pytask
1515
invoking_pytask_extended
1616
capture_warnings
17-
repeating_tasks_with_different_inputs_the_pytest_way
1817
how_to_influence_build_order
1918
how_to_write_a_plugin
2019
```

docs/source/how_to_guides/repeating_tasks_with_different_inputs_the_pytest_way.md

Lines changed: 0 additions & 213 deletions
This file was deleted.

docs/source/reference_guides/api.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,6 @@ by the host or by plugins. The following marks are available by default.
4747
:func:`_pytask.hookspecs.pytask_collect_node` entry-point.
4848
```
4949

50-
```{eval-rst}
51-
.. function:: pytask.mark.parametrize(arg_names, arg_values, *, ids)
52-
53-
Parametrize a task function.
54-
55-
Parametrizing a task allows to execute the same task with different arguments.
56-
57-
:type arg_names: str | list[str] | tuple[str, ...]
58-
:param arg_names:
59-
The names of the arguments which can either be given as a comma-separated
60-
string, a tuple of strings, or a list of strings.
61-
:type arg_values: Iterable[Sequence[Any] | Any]
62-
:param arg_values:
63-
The values which correspond to names in ``arg_names``. For one argument, it is a
64-
single iterable. For multiple argument names it is an iterable of iterables.
65-
:type ids: None | (Iterable[None | str | float | int | bool] | Callable[..., Any])
66-
:param ids:
67-
This argument can either be a list with ids or a function which is called with
68-
every value passed to the parametrized function.
69-
70-
If you pass an iterable with ids, make sure to only use :obj:`bool`,
71-
:obj:`float`, :obj:`int`, or :obj:`str` as values which are used to create task
72-
ids like ``"task_dummpy.py::task_dummy[first_task_id]"``.
73-
74-
If you pass a function, the function receives each value of the parametrization
75-
and may return a boolean, number, string or None. For the latter, the
76-
auto-generated value is used.
77-
```
78-
7950
```{eval-rst}
8051
.. function:: pytask.mark.persist()
8152

docs/source/reference_guides/hookspecs.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,6 @@ The following hooks traverse directories and collect tasks from files.
106106
107107
```
108108

109-
## Parametrization
110-
111-
The hooks to parametrize a task are called during the collection when a function is
112-
collected. Then, the function is duplicated according to the parametrization and the
113-
duplicates are collected with {func}`pytask_collect_task`.
114-
115-
```{eval-rst}
116-
.. autofunction:: pytask_parametrize_task
117-
```
118-
119-
```{eval-rst}
120-
.. autofunction:: pytask_parametrize_kwarg_to_marker
121-
122-
```
123-
124109
## Resolving Dependencies
125110

126111
The following hooks are designed to build a DAG from tasks and dependencies and check

docs/source/tutorials/repeating_tasks_with_different_inputs.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

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

5-
:::{important}
6-
Before v0.2.0, pytask supported only one approach to repeat tasks. It is also called
7-
parametrizations, and similarly to pytest, it uses a
8-
{func}`@pytask.mark.parametrize <pytask.mark.parametrize>` decorator. If you want to
9-
know more about it, you can find it
10-
{doc}`here <../how_to_guides/repeating_tasks_with_different_inputs_the_pytest_way>`.
11-
12-
Here you find the new and preferred approach.
13-
:::
14-
155
## An example
166

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

7363
This behavior would produce duplicate ids for parametrized tasks. By default,
74-
auto-generated ids are used which are explained {ref}`here <auto-generated-ids>`.
64+
auto-generated ids are used.
65+
66+
(auto-generated-ids)=
67+
68+
### Auto-generated ids
69+
70+
pytask construct ids by extending the task name with representations of the values used
71+
for each iteration. Booleans, floats, integers, and strings enter the task id directly.
72+
For example, a task function that receives four arguments, `True`, `1.0`, `2`, and
73+
`"hello"`, one of each dtype, has the following id.
74+
75+
```
76+
task_data_preparation.py::task_create_random_data[True-1.0-2-hello]
77+
```
78+
79+
Arguments with other dtypes cannot be converted to strings and, thus, are replaced with
80+
a combination of the argument name and the iteration counter.
7581

76-
More powerful are user-defined ids.
82+
For example, the following function is parametrized with tuples.
83+
84+
```python
85+
for i in [(0,), (1,)]:
86+
87+
@pytask.mark.task
88+
def task_create_random_data(i=i):
89+
pass
90+
```
91+
92+
Since the tuples are not converted to strings, the ids of the two tasks are
93+
94+
```
95+
task_data_preparation.py::task_create_random_data[i0]
96+
task_data_preparation.py::task_create_random_data[i1]
97+
```
7798

7899
(ids)=
79100

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ extend-ignore = [
6262
"SLF001", # access private members.
6363
"S603",
6464
"S607",
65+
# Temporary
66+
"TD002",
67+
"TD003",
6568
]
6669

6770

src/_pytask/cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def pytask_add_hooks(pm: pluggy.PluginManager) -> None:
6666
from _pytask import mark
6767
from _pytask import nodes
6868
from _pytask import parameters
69-
from _pytask import parametrize
7069
from _pytask import persist
7170
from _pytask import profile
7271
from _pytask import dag
@@ -89,7 +88,6 @@ def pytask_add_hooks(pm: pluggy.PluginManager) -> None:
8988
pm.register(mark)
9089
pm.register(nodes)
9190
pm.register(parameters)
92-
pm.register(parametrize)
9391
pm.register(persist)
9492
pm.register(profile)
9593
pm.register(dag)

0 commit comments

Comments
 (0)