[e988c2]: / tests / spec / case_expressions / test_when.py

Download this file

52 lines (43 with data), 856 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from ehrql import when
from ..tables import p
title = "Case expressions with single condition"
def test_when_with_expression(spec_test):
table_data = {
p: """
| i1
--+----
1 | 6
2 | 7
3 | 8
4 |
""",
}
spec_test(
table_data,
when(p.i1 < 8).then(p.i1).otherwise(100),
{
1: 6,
2: 7,
3: 100,
4: 100,
},
)
def test_when_with_boolean_column(spec_test):
table_data = {
p: """
| i1 | b1
--+----+----
1 | 6 | T
2 | 7 | F
3 | |
""",
}
spec_test(
table_data,
when(p.b1).then(p.i1).otherwise(100),
{
1: 6,
2: 100,
3: 100,
},
)