forked from eu-parc/dataguard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecks.py
More file actions
131 lines (109 loc) · 3.34 KB
/
Copy pathchecks.py
File metadata and controls
131 lines (109 loc) · 3.34 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import polars as pl
from dataguard import Validator, ErrorCollector
def is_between(data, arg_values=None, arg_columns=None, subject=None):
return data.lazyframe.select(
pl.col(data.key).is_between(arg_values[0], arg_values[1], closed='left')
)
config_age = {
'name': 'Age must be not null, grater than or equal to 0 and less than 150',
'columns': [
{
'id': 'age',
'data_type': 'integer',
'nullable': False,
'unique': False,
'required': True,
'checks': [
{
'name': 'Tailor-made function check: is_between',
'error_level': 'warning',
'error_msg': 'Age must be between 0 (inclusive) and 150 (exclusive)',
'command': is_between,
'arg_values': [0, 150],
},
],
},
],
'ids': [],
'metadata': {},
'checks': [],
}
df_age = pl.DataFrame({
'age': [2, 30, None, -5, 150, 45, 50],
})
validator = Validator.config_from_mapping(config_age)
validator.validate(df_age)
ErrorCollector().get_errors()
import polars as pl
from dataguard import Validator, ErrorCollector
def is_between(data, arg_values=None, arg_columns=None, subject=None):
return data.lazyframe.select(
pl.col(data.key).is_between(arg_values[0], arg_values[1], closed='left')
)
config_age = {
'name': 'Age must be not null, grater than or equal to 0 and less than 150',
'columns': [
{
'id': 'age',
'data_type': 'integer',
'nullable': False,
'unique': False,
'required': True,
'checks': [
{
'name': 'Tailor-made function check: is_between',
'error_level': 'warning',
'error_msg': 'Age must be between 0 (inclusive) and 150 (exclusive)',
'command': is_between,
'arg_values': [0, 150],
},
],
},
],
'ids': [],
'metadata': {},
'checks': [],
}
df_age = pl.DataFrame({
'age': [2, 30, None, -5, 150, 45, 50],
})
validator = Validator.config_from_mapping(config_age)
validator.validate(df_age)
ErrorCollector().get_errors()
ErrorCollector().clear_errors()
config_age = {
'name': 'Age must be not null, grater than or equal to 0 and less than 150',
'columns': [
{
'id': 'age',
'data_type': 'integer',
'nullable': False,
'unique': False,
'required': True,
'checks': [
{
'check_case': 'conjunction',
'expressions': [
{
'command': 'is_greater_than_or_equal_to',
'arg_values': [0]
},
{
'command': 'is_less_than',
'arg_values': [150]
}
]
},
]
},
],
'ids': [],
'metadata': {},
'checks': [],
}
df_age = pl.DataFrame({
'age': [2, 30, None, -5, 150, 45, 50],
})
validator = Validator.config_from_mapping(config_age)
validator.validate(df_age)
ErrorCollector().get_errors()