DataQualityExpectation
laktory.models.DataQualityExpectation
¤
Bases: BaseModel
Data Quality Expectation for a given DataFrame expressed as a row-specific
condition (type="ROW"
) or as an aggregated metric (type="AGGREGATE"
).
The expression may be defined as a SQL statement or a DataFrame expression.
ATTRIBUTE | DESCRIPTION |
---|---|
action |
Action to take when expectation is not met.
TYPE:
|
type |
Type of expectation:
TYPE:
|
name |
Name of the expectation
TYPE:
|
expr |
SQL or DataFrame expression representing a row-specific condition or an aggregated metric.
TYPE:
|
tolerance |
Tolerance for non-matching rows before resulting in failure. Only available for "ROW" type expectation.
TYPE:
|
Examples:
from laktory import models
dqe = models.DataQualityExpectation(
name="price higher than 10",
action="WARN",
expr="close > 127",
tolerance={"rel": 0.05},
)
print(dqe)
'''
variables={} action='WARN' type='ROW' name='price higher than 10' expr=DataFrameColumnExpression(variables={}, value='close > 127', type='SQL') tolerance=ExpectationTolerance(variables={}, abs=None, rel=0.05)
'''
dqe = models.DataQualityExpectation(
name="rows count",
expr="COUNT(*) > 50",
type="AGGREGATE",
)
print(dqe)
'''
variables={} action='WARN' type='AGGREGATE' name='rows count' expr=DataFrameColumnExpression(variables={}, value='COUNT(*) > 50', type='SQL') tolerance=ExpectationTolerance(variables={}, abs=0, rel=None)
'''
References
METHOD | DESCRIPTION |
---|---|
run_check |
Check if expectation is met save result. |
raise_or_warn |
Raise exception or issue warning if expectation is not met. |
ATTRIBUTE | DESCRIPTION |
---|---|
pass_filter |
Expression representing all rows meeting the expectation.
TYPE:
|
fail_filter |
Expression representing all rows not meeting the expectation.
TYPE:
|
keep_filter |
Expression representing all rows to keep, considering both the
TYPE:
|
quarantine_filter |
Expression representing all rows to quarantine, considering both the
TYPE:
|
Attributes¤
keep_filter
property
¤
keep_filter
Expression representing all rows to keep, considering both the expectation and the selected action.
quarantine_filter
property
¤
quarantine_filter
Expression representing all rows to quarantine, considering both the expectation and the selected action.
Functions¤
run_check
¤
run_check(df, raise_or_warn=False, node=None)
Check if expectation is met save result.
PARAMETER | DESCRIPTION |
---|---|
df
|
Input DataFrame for checking the expectation.
TYPE:
|
raise_or_warn
|
Raise exception or issue warning if expectation is not met.
TYPE:
|
node
|
Pipeline Node
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
output
|
Check result.
TYPE:
|
Source code in laktory/models/dataquality/expectation.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
raise_or_warn
¤
raise_or_warn(node=None)
Raise exception or issue warning if expectation is not met.
Source code in laktory/models/dataquality/expectation.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
|