Skip to content

Commit d412280

Browse files
committed
Update actions.qmd
1 parent 099312b commit d412280

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

docs/user-guide/actions.qmd

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ could take the form of a console message).
2222
Let's look at an example on how this works in practice. The following validation plan contains a
2323
single step (using
2424
[`col_vals_gt()`](https://posit-dev.github.io/pointblank/reference/Validate.col_vals_gt.html)) where
25-
the `thresholds=` and `actions=` parameters are set:
25+
the `thresholds=` and `actions=` parameters are set using
26+
[`Thresholds`](https://posit-dev.github.io/pointblank/reference/Thresholds.html) and
27+
[`Actions`](https://posit-dev.github.io/pointblank/reference/Actions.html) calls:
2628

2729
```{python}
2830
import pointblank as pb
@@ -72,17 +74,55 @@ an action.
7274

7375
There are a few options in how to define the actions:
7476

75-
1. **String**: A message to be displayed in the console.
76-
2. **Callable**: A function to be called (which could do virtually anything).
77-
3. **List of Strings/Callables**: For execution of multiple messages or functions.
77+
1. **String**: a message to be displayed in the console
78+
2. **Callable**: a function to be called
79+
3. **List of Strings/Callables**: for execution of multiple messages or functions
7880

7981
The actions are executed at interrogation time when the threshold level assigned to the action
8082
is exceeded by the number or proportion of failing test units. When providing a string, it will
8183
simply be printed to the console. A callable will also be executed at the time of interrogation.
8284
If providing a list of strings or callables, each item in the list will be executed in order.
8385
Such a list can contain a mix of strings and callables.
8486

85-
Here's an example where we use a custom function as part of an action:
87+
Displaying console messages may be a simple approach, but it is effective. And the strings don't
88+
have to be static, there are templating features that can be useful for constructing strings for a
89+
variety of situations. The following placeholders are available for use:
90+
91+
- `{type}`: The validation step type where the action is executed (e.g., ‘col_vals_gt’, etc.)
92+
- `{level}`: The threshold level where the action is executed (‘warning’, ‘error’, or ‘critical’)
93+
- `{step}` or `{i}`: The step number in the validation workflow where the action is executed
94+
- `{col}` or `{column}`: The column name where the action is executed
95+
- `{val}` or `{value}`: An associated value for the validation method
96+
- `{time}`: A datetime value for when the action was executed
97+
98+
Here's an example where we prepare a console message with a number of value placeholders
99+
(`action_str`) and use it globally at `Actions(critical=)`:
100+
101+
```{python}
102+
103+
action_str = "[{LEVEL}: {TYPE}]: Step {step} has failed validation. ({time})"
104+
105+
validation = (
106+
pb.Validate(
107+
data=pb.load_dataset(dataset="game_revenue", tbl_type="duckdb"),
108+
thresholds=pb.Thresholds(warning=0.05, error=0.10, critical=0.15),
109+
actions=pb.Actions(critical=action_str),
110+
)
111+
.col_vals_regex(columns="player_id", pattern=r"[A-Z]{12}\d{3}")
112+
.col_vals_gt(columns="item_revenue", value=0.10)
113+
.col_vals_ge(columns="session_duration", value=15)
114+
.interrogate()
115+
)
116+
```
117+
118+
What we get here are two messages in the console, corresponding to critical failures in steps 2 and
119+
3. The placeholders were replaced with the correct text for the context. Note that some of the
120+
resulting text is capitalized (e.g., `"CRITICAL"`, `"COL_VALS_GT"`, etc.) and this is because we
121+
capitalized the placeholder text itself. Have a look at the documentation article of
122+
[`Actions`](https://posit-dev.github.io/pointblank/reference/Actions.html) for more details on this.
123+
124+
Aside from strings, any callable can be used as an action value. Here's an example where we use a
125+
custom function as part of an action:
86126

87127
```{python}
88128
def dq_issue():

0 commit comments

Comments
 (0)