Checks¶
Module containing data quality check classes.
AverageCheck ¶
AverageCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, *, transformation_name: str | None = None, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Compute the average (AVG) of a numeric column for the filtered rows.
Takes the arguments of ColumnTransformationCheck and the options in
CheckOptions. Thresholds apply to the computed average.
Source code in src/koality/checks.py
transformation_statement ¶
CheckOptions ¶
Bases: TypedDict
Keyword options shared by all checks, passed as **options.
Attributes:
| Name | Type | Description |
|---|---|---|
filters |
dict[str, Any] | None
|
The check's filters by name, each with |
identifier_format |
str
|
How the identifier filter appears in results: "identifier" ( |
identifier_placeholder |
str
|
The identifier shown when the identifier filter has no value (default "ALL"). |
date_info |
str | None
|
Text shown after the date in the failure message. |
extra_info |
str | None
|
Text appended to the failure message. |
monitor_only |
bool
|
If True, the result isn't compared to the thresholds, so the check doesn't fail the run (missing data and query errors still do). |
ColumnTransformationCheck ¶
ColumnTransformationCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, *, transformation_name: str | None = None, **options: Unpack[CheckOptions])
Bases: DataQualityCheck, ABC
Abstract class for data quality checks performing checks on a specific column of a table.
Subclasses set transformation_name as a class attribute and implement transformation_statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_accessor
|
str
|
The attached database the check reads from (e.g. "bq"); empty for tables in DuckDB itself. |
required |
database_provider
|
DatabaseProvider | None
|
The attached database, which picks the backend (None for DuckDB itself). |
required |
table
|
str
|
The table to check, in the database_accessor's catalog (e.g. "orders"); in BigQuery, as BigQuery names it (e.g. "dataset.table"). |
required |
check_column
|
str
|
The column to check (e.g. "category"). |
required |
lower_threshold
|
float
|
The check fails if its result is below this. |
-inf
|
upper_threshold
|
float
|
The check fails if its result is above this. |
inf
|
transformation_name
|
str | None
|
Overrides the class's |
None
|
Further keyword options: see CheckOptions.
Source code in src/koality/checks.py
assemble_data_exists_query ¶
Assemble the SQL query to check if data exists in the table.
Source code in src/koality/checks.py
assemble_name ¶
assemble_query ¶
Assemble the complete SQL query for this check.
Source code in src/koality/checks.py
query_boilerplate ¶
Return the base SQL query structure with the given metric statement.
transformation_statement
abstractmethod
¶
CountCheck ¶
CountCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, *, distinct: bool = False, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Check the number of rows or distinct values of a specific column.
Takes the arguments of ColumnTransformationCheck (except
transformation_name) and the options in CheckOptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distinct
|
bool
|
Indicates if the count should count all rows or only distinct values of a specific column. Note: distinct=True cannot be used with check_column="*". |
False
|
Example
from koality.checks import CountCheck
CountCheck(
database_accessor="",
database_provider=None,
table="skufeed_latest",
check_column="sku_id",
distinct=True,
filters={
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
"date": {"column": "DATE", "value": "2023-01-01", "type": "date"},
},
lower_threshold=10000.0,
upper_threshold=99999.0,
)
Source code in src/koality/checks.py
DataQualityCheck ¶
DataQualityCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str | None = None, lower_threshold: float = -inf, upper_threshold: float = inf, *, filters: dict[str, Any] | None = None, identifier_format: str = 'identifier', identifier_placeholder: str = 'ALL', date_info: str | None = None, extra_info: str | None = None, monitor_only: bool = False)
Bases: ABC
Abstract class for all data quality checks.
Provides generic methods relevant to all data quality check classes. koality run creates the checks from the
YAML configuration (see create_checks); the checks' examples create one
directly, for a table in DuckDB itself (an empty database_accessor).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_accessor
|
str
|
The attached database the check reads from (e.g. "bq"); empty for tables in DuckDB itself. |
required |
database_provider
|
DatabaseProvider | None
|
The attached database, which picks the backend (None for DuckDB itself). |
required |
table
|
str
|
The table to check, in the database_accessor's catalog (e.g. "orders"); in BigQuery, as BigQuery names it (e.g. "dataset.table"). |
required |
check_column
|
str | None
|
The column to check (e.g. "category"). |
None
|
lower_threshold
|
float
|
The check fails if its result is below this. |
-inf
|
upper_threshold
|
float
|
The check fails if its result is above this. |
inf
|
The keyword-only arguments are the options in CheckOptions.
Source code in src/koality/checks.py
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
in_memory_column
property
¶
Return the column name to reference in in-memory queries.
If a configured column references a nested field (e.g. "value.shopId"): - When querying data loaded via database_accessor: uses underscores ("value_shopId") because the executor flattens struct columns with underscore aliases - When querying existing DuckDB tables (no accessor): keeps dots ("value.shopId") to support native DuckDB struct column syntax
This property provides the appropriate name without modifying the original
configured self.check_column which is still used for result writing.
__call__ ¶
Execute the data quality check and return results.
Source code in src/koality/checks.py
__repr__ ¶
Return string representation combining identifier and check name.
assemble_data_exists_query
abstractmethod
¶
assemble_name
abstractmethod
¶
assemble_query
abstractmethod
¶
assemble_where_statement
staticmethod
¶
assemble_where_statement(filters: dict[str, dict[str, Any]], *, strip_dotted_columns: bool = True, database_accessor: str | None = None, dialect: SqlDialect = DUCKDB_DIALECT) -> str
Generate the where statement for the check query using the specified filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
dict[str, dict[str, Any]]
|
A dict containing filter specifications (see the example below). |
required |
strip_dotted_columns
|
bool
|
When True (default), dotted column names (e.g. "a.b") are transformed based on the data source:
If False, the full dotted expression is preserved regardless (used when querying source databases that expect the original dotted column syntax). |
True
|
database_accessor
|
str | None
|
Optional database accessor string. When provided and non-empty, indicates data was loaded from external source and dotted columns should be converted to underscores. |
None
|
dialect
|
SqlDialect
|
How values, date columns and date literals are written (DuckDB by default; the fetch query uses the source's backend, e.g. BigQuery literals). |
DUCKDB_DIALECT
|
Example
from koality.checks import DataQualityCheck
filters = {
"identifier": {"column": "shop_code", "value": "SHOP01", "operator": "=", "type": "identifier"},
"date": {"column": "date", "value": "2023-01-01", "operator": "=", "type": "date"},
"revenue": {"column": "total_revenue", "value": 1000, "operator": ">="},
"category": {"column": "category", "value": ["toys", "electronics"], "operator": "IN"},
}
DataQualityCheck.assemble_where_statement(filters)
Returns:
| Type | Description |
|---|---|
str
|
A WHERE statement to restrict the data being used for the check, e.g. for the example
|
Source code in src/koality/checks.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
check ¶
Perform the data quality check and return results.
If the check is set to monitor_only, the results of the
check will be documented without comparison to the lower and
upper thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duckdb_client
|
DuckDBPyConnection
|
DuckDB client for interacting with DuckDB |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dict containing all information and the result of the check |
Source code in src/koality/checks.py
data_check ¶
Check if database tables used in the actual check contain data.
Note: The returned result dict and failure message will be later aggregated in order to avoid duplicates in the reported failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duckdb_client
|
DuckDBPyConnection
|
DuckDB client for interacting with DuckDB |
required |
Returns:
| Type | Description |
|---|---|
dict
|
If there is a table without data, a dict containing information about |
dict
|
missing data will be returned, otherwise an empty dict indicating that |
dict
|
data exists. |
Source code in src/koality/checks.py
get_date_filter
staticmethod
¶
Find the date filter (type='date') from the filters dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
dict[str, dict[str, Any]]
|
The filters dict from get_filters(). |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, dict[str, Any]] | None
|
A tuple of (filter_name, filter_config) if found, None otherwise. |
Source code in src/koality/checks.py
get_filters
staticmethod
¶
Generate a filter dict from filter configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters_config
|
dict[str, Any]
|
Dictionary containing filter configurations. |
required |
Example
filters:
partition_date:
column: BQ_PARTITIONTIME
value: yesterday-2 # 2 days before yesterday
type: date # auto-parses value as date
shop_id:
column: shopId
value: EC0601
type: identifier
revenue:
column: total_revenue
value: 1000
operator: ">="
category:
column: category
value: ["toys", "electronics"]
operator: "IN"
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dict of the format
|
Source code in src/koality/checks.py
get_identifier_filter
staticmethod
¶
Find the identifier filter (type='identifier') from the filters dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
dict[str, dict[str, Any]]
|
The filters dict from get_filters(). |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, dict[str, Any]] | None
|
A tuple of (filter_name, filter_config) if found, None otherwise. |
Source code in src/koality/checks.py
source_tables ¶
table_ref ¶
Return the reference to use for table in in-memory queries.
Data fetched by the executor lives in the staging catalog (see
CheckExecutor.fetch_data_into_memory); otherwise the table is queried as-is.
Source code in src/koality/checks.py
DuplicateCheck ¶
DuplicateCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, *, transformation_name: str | None = None, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Check the number of duplicates for a specific column.
Counts all rows minus distinct counts. Takes the arguments of
ColumnTransformationCheck and the options in
CheckOptions.
Example
from koality.checks import DuplicateCheck
DuplicateCheck(
database_accessor="",
database_provider=None,
table="skufeed_latest",
check_column="sku_id",
filters={
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
"date": {"column": "DATE", "value": "2023-01-01", "type": "date"},
},
lower_threshold=0.0,
upper_threshold=0.0,
)
Source code in src/koality/checks.py
transformation_statement ¶
IqrOutlierCheck ¶
IqrOutlierCheck(database_accessor: str, database_provider: DatabaseProvider | None, check_column: str, table: str, interval_days: int, how: Literal['both', 'upper', 'lower'], iqr_factor: float, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Check if a column value is an outlier based on the interquartile range (IQR) method.
Takes the arguments of ColumnTransformationCheck (except
lower_threshold, upper_threshold and transformation_name) and the options in
CheckOptions. Its filters must include a filter with type: date.
The IQR method is based on the 25th and 75th percentiles of the data. The thresholds are calculated as follows:
- lower_threshold = q25 - iqr_factor * (q75 - q25)
- upper_threshold = q75 + iqr_factor * (q75 - q25)
Note: lower_threshold and upper_threshold are calculated internally and should
not be provided directly in the configuration for IqrOutlierCheck.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval_days
|
int
|
Number of historic days to use for IQR calculation. |
required |
how
|
Literal['both', 'upper', 'lower']
|
Check mode - 'both', 'upper', or 'lower' outliers. |
required |
iqr_factor
|
float
|
Multiplier for IQR range (minimum 1.5). |
required |
Example
from koality.checks import IqrOutlierCheck
IqrOutlierCheck(
database_accessor="",
database_provider=None,
check_column="num_orders",
table="orders",
interval_days=14,
how="both",
iqr_factor=1.5,
filters={
"partition_date": {"column": "DATE", "value": "2023-01-01", "type": "date"},
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
},
)
Source code in src/koality/checks.py
assemble_data_exists_query ¶
Assemble the query to check if data exists for IQR outlier detection.
Source code in src/koality/checks.py
query_boilerplate ¶
Return the query structure for IQR outlier detection.
transformation_statement ¶
Return the SQL statement for IQR-based outlier detection.
Source code in src/koality/checks.py
MatchRateCheck ¶
MatchRateCheck(database_accessor: str, database_provider: DatabaseProvider | None, left_table: str, right_table: str, check_column: str, join_columns: list[str] | None = None, join_columns_left: list[str] | None = None, join_columns_right: list[str] | None = None, lower_threshold: float = -inf, upper_threshold: float = inf, *, filters_left: dict[str, Any] | None = None, filters_right: dict[str, Any] | None = None, **options: Unpack[CheckOptions])
Bases: DataQualityCheck
Checks the match rate between two tables after joining on specific columns.
If left_join_columns (or right_join_columns) is defined, these columns will be used for joining the data. If not, join_columns will be used as fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_table
|
str
|
The table whose rows are matched, the left side of the join (e.g. "pdp_views", or "dataset.pdp_views" in BigQuery). |
required |
right_table
|
str
|
The table they are matched against, the right side of the join (e.g. "skufeed_latest"). |
required |
check_column
|
str
|
Name of column to be checked (e.g., "product_number") |
required |
join_columns
|
list[str] | None
|
List of columns to join data on (e.g., ["PREDICTION_DATE", "product_number"]) |
None
|
join_columns_left
|
list[str] | None
|
List of columns of left table to join data on (e.g., ["BQ_PARTITIONTIME", "productId"]) |
None
|
join_columns_right
|
list[str] | None
|
List of columns of right table to join data on (e.g., ["PREDICTION_DATE", "product_number"]) |
None
|
lower_threshold
|
float
|
The check fails if its result is below this. |
-inf
|
upper_threshold
|
float
|
The check fails if its result is above this. |
inf
|
filters_left
|
dict[str, Any] | None
|
Filters for the left table only, applied on top of |
None
|
filters_right
|
dict[str, Any] | None
|
Filters for the right table only, applied on top of |
None
|
database_accessor and database_provider are as in DataQualityCheck.
Further keyword options (e.g. filters, applied to both tables): see CheckOptions.
Example
from koality.checks import MatchRateCheck
MatchRateCheck(
database_accessor="",
database_provider=None,
left_table="pdp_views",
right_table="skufeed_latest",
join_columns_left=["DATE", "product_number_v2"],
join_columns_right=["DATE", "product_number"],
check_column="product_number",
filters={
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
"date": {"column": "DATE", "value": "2023-01-01", "type": "date"},
},
filters_left={
"status": {"column": "order_status", "value": "completed"},
},
filters_right={
"active": {"column": "is_active", "value": True},
},
)
Source code in src/koality/checks.py
assemble_data_exists_query ¶
First checks left, then right table for data.
Returns:
| Type | Description |
|---|---|
str
|
Empty table name or empty string |
Source code in src/koality/checks.py
assemble_name ¶
assemble_query ¶
Assemble the SQL query for calculating match rate between tables.
Source code in src/koality/checks.py
source_tables ¶
MaxCheck ¶
MaxCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, *, transformation_name: str | None = None, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Compute the maximum (MAX) of a column for the filtered rows.
Takes the arguments of ColumnTransformationCheck and the options in
CheckOptions. Thresholds apply to the computed maximum.
Source code in src/koality/checks.py
transformation_statement ¶
MinCheck ¶
MinCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, *, transformation_name: str | None = None, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Compute the minimum (MIN) of a column for the filtered rows.
Takes the arguments of ColumnTransformationCheck and the options in
CheckOptions. Thresholds apply to the computed minimum.
Source code in src/koality/checks.py
transformation_statement ¶
NullRatioCheck ¶
NullRatioCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, *, transformation_name: str | None = None, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Check the share of NULL values in a specific column of a table.
Takes the arguments of ColumnTransformationCheck and the options in
CheckOptions.
Example
from koality.checks import NullRatioCheck
NullRatioCheck(
database_accessor="",
database_provider=None,
table="orders",
check_column="order_id",
filters={
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
"date": {"column": "date", "value": "2023-01-01", "type": "date"},
},
lower_threshold=0.9,
upper_threshold=1.0,
)
Source code in src/koality/checks.py
transformation_statement ¶
Return the SQL statement for calculating null ratio.
Source code in src/koality/checks.py
OccurrenceCheck ¶
OccurrenceCheck(database_accessor: str, database_provider: DatabaseProvider | None, max_or_min: Literal['max', 'min'], table: str, check_column: str, lower_threshold: float = -inf, upper_threshold: float = inf, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Check how often any value in a column occurs.
Useful e.g. to check for a single product occurring unusually often (likely an error). Takes the arguments of
ColumnTransformationCheck (except transformation_name) and the
options in CheckOptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_or_min
|
Literal['max', 'min']
|
Check either the maximum or minimum occurrence of any value.
|
required |
Example
from koality.checks import OccurrenceCheck
OccurrenceCheck(
database_accessor="",
database_provider=None,
max_or_min="max",
table="skufeed_latest",
check_column="sku_id",
filters={
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
"date": {"column": "DATE", "value": "2023-01-01", "type": "date"},
},
lower_threshold=0,
upper_threshold=500,
)
Source code in src/koality/checks.py
assemble_query ¶
Assemble query to find max or min occurrence of any value.
Source code in src/koality/checks.py
transformation_statement ¶
RegexMatchCheck ¶
RegexMatchCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, regex_to_match: str, lower_threshold: float = -inf, upper_threshold: float = inf, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Check the share of values matching a regex in a specific column of a table.
Takes the arguments of ColumnTransformationCheck (except
transformation_name) and the options in CheckOptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regex_to_match
|
str
|
The regular expression to be checked on check_column (e.g., "SHOP[0-9]{2}-.*" to check for a shop code prefix like "SHOP01-") |
required |
Example
from koality.checks import RegexMatchCheck
RegexMatchCheck(
database_accessor="",
database_provider=None,
table="orders",
check_column="order_id",
regex_to_match="^SHOP[0-9]{2}-.*",
filters={"date": {"column": "date", "value": "2023-01-01", "type": "date"}},
lower_threshold=0.9,
upper_threshold=1.0,
)
Source code in src/koality/checks.py
transformation_statement ¶
Return the SQL statement for calculating regex match ratio.
RelCountChangeCheck ¶
RelCountChangeCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, rolling_days: int, lower_threshold: float = -inf, upper_threshold: float = inf, **options: Unpack[CheckOptions])
Bases: DataQualityCheck
Check the relative change of a count compared to historic average.
Compares the count to the average counts of a number of historic days before the check date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
The table to check (e.g. "feature_category", or "dataset.feature_category" in BigQuery). |
required |
check_column
|
str
|
The column whose distinct values are counted per day (e.g. "category"), or "*" to count rows. |
required |
rolling_days
|
int
|
The number of historic days to be taken into account for the historic average baseline for the comparison (e.g., 7). |
required |
lower_threshold
|
float
|
The check fails if its result is below this. |
-inf
|
upper_threshold
|
float
|
The check fails if its result is above this. |
inf
|
database_accessor and database_provider are as in DataQualityCheck.
Further keyword options: see CheckOptions; filters must include a filter with
type: date, with column and value.
Example
from koality.checks import RelCountChangeCheck
RelCountChangeCheck(
database_accessor="",
database_provider=None,
table="skufeed_latest",
check_column="sku_id",
rolling_days=7,
filters={
"partition_date": {"column": "DATE", "value": "2023-01-01", "type": "date"},
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
},
lower_threshold=-0.15,
upper_threshold=0.15,
)
Source code in src/koality/checks.py
assemble_data_exists_query ¶
Assemble the SQL query to check if data exists for the check date.
Source code in src/koality/checks.py
assemble_name ¶
Return the check name for count change, row_count_change for a row count ("*").
assemble_query ¶
Assemble the SQL query for calculating relative count change.
Source code in src/koality/checks.py
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 | |
RollingValuesInSetCheck ¶
RollingValuesInSetCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, value_set: str | bytes | Iterable, lower_threshold: float = -inf, upper_threshold: float = inf, **options: Unpack[CheckOptions])
Bases: ValuesInSetCheck
Check share of values matching a value set over a rolling time period.
Similar to ValuesInSetCheck, but the share is computed for a longer time period
(currently also including data of the 14 days before the actual check date).
Takes the arguments of ValuesInSetCheck (except transformation_name) and
the options in CheckOptions; filters must include a filter with type: date,
with column and value.
Example
from koality.checks import RollingValuesInSetCheck
RollingValuesInSetCheck(
database_accessor="",
database_provider=None,
table="orders",
check_column="category",
value_set='("toys", "shoes")',
filters={
"partition_date": {"column": "DATE", "value": "2023-01-01", "type": "date"},
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
},
lower_threshold=0.9,
upper_threshold=1.0,
)
Source code in src/koality/checks.py
assemble_query ¶
Assemble query with rolling date range for values in set check.
Source code in src/koality/checks.py
ValuesInSetCheck ¶
ValuesInSetCheck(database_accessor: str, database_provider: DatabaseProvider | None, table: str, check_column: str, value_set: str | bytes | Iterable, lower_threshold: float = -inf, upper_threshold: float = inf, *, transformation_name: str | None = None, **options: Unpack[CheckOptions])
Bases: ColumnTransformationCheck
Check the share of values that match any value of a value set in a column.
Takes the arguments of ColumnTransformationCheck and the options in
CheckOptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value_set
|
str | bytes | Iterable
|
A list of values (or a string representation of such a list) to be checked. Single values are also allowed. Examples for valid inputs:
|
required |
Example
from koality.checks import ValuesInSetCheck
ValuesInSetCheck(
database_accessor="",
database_provider=None,
table="orders",
check_column="category",
value_set='("toys", "shoes")',
filters={
"identifier": {"column": "shop_code", "value": "SHOP01", "type": "identifier"},
"date": {"column": "date", "value": "2023-01-01", "type": "date"},
},
lower_threshold=0.9,
upper_threshold=1.0,
)
Source code in src/koality/checks.py
transformation_statement ¶
Return the SQL statement for calculating values in set ratio.
staged_table_ref ¶
Return the fully qualified reference of table in a staging catalog.
validate_table_name ¶
Raise KoalityError if name cannot be parsed or has more than catalog.schema.table parts.