Module sumeh.engine.pandas_engine
¶
This module provides a set of data quality validation functions using the Pandas library. It includes various checks for data validation, such as completeness, uniqueness, range checks, pattern matching, date validations, SQL-style custom expressions, and schema validation.
Functions:
Name | Description |
---|---|
is_positive |
Filters rows where the specified field is less than zero. |
is_negative |
Filters rows where the specified field is greater than or equal to zero. |
is_in_millions |
Retains rows where the field value is at least 1,000,000 and flags them with dq_status. |
is_in_billions |
Retains rows where the field value is at least 1,000,000,000 and flags them with dq_status. |
is_t_minus_1 |
Retains rows where the date field equals yesterday (T-1) and flags them with dq_status. |
is_t_minus_2 |
Retains rows where the date field equals two days ago (T-2) and flags them with dq_status. |
is_t_minus_3 |
Retains rows where the date field equals three days ago (T-3) and flags them with dq_status. |
is_today |
Retains rows where the date field equals today and flags them with dq_status. |
is_yesterday |
Retains rows where the date field equals yesterday and flags them with dq_status. |
is_on_weekday |
Retains rows where the date field falls on a weekday (Mon-Fri) and flags them with dq_status. |
is_on_weekend |
Retains rows where the date field is on a weekend (Sat-Sun) and flags them with dq_status. |
is_on_monday |
Retains rows where the date field is on Monday and flags them with dq_status. |
is_on_tuesday |
Retains rows where the date field is on Tuesday and flags them with dq_status. |
is_on_wednesday |
Retains rows where the date field is on Wednesday and flags them with dq_status. |
is_on_thursday |
Retains rows where the date field is on Thursday and flags them with dq_status. |
is_on_friday |
Retains rows where the date field is on Friday and flags them with dq_status. |
is_on_saturday |
Retains rows where the date field is on Saturday and flags them with dq_status. |
is_on_sunday |
Retains rows where the date field is on Sunday and flags them with dq_status. |
is_complete |
Filters rows where the specified field is null. |
is_unique |
Filters rows with duplicate values in the specified field. |
are_complete |
Filters rows where any of the specified fields are null. |
are_unique |
Filters rows with duplicate combinations of the specified fields. |
is_greater_than |
Filters rows where the specified field is less than or equal to the given value. |
is_greater_or_equal_than |
Filters rows where the specified field is less than the given value. |
is_less_than |
Filters rows where the specified field is greater than or equal to the given value. |
is_less_or_equal_than |
Filters rows where the specified field is greater than the given value. |
is_equal |
Filters rows where the specified field is not equal to the given value. |
is_equal_than |
Alias for |
is_contained_in |
Filters rows where the specified field is not in the given list of values. |
not_contained_in |
Filters rows where the specified field is in the given list of values. |
is_between |
Filters rows where the specified field is not within the given range. |
has_pattern |
Filters rows where the specified field does not match the given regex pattern. |
is_legit |
Filters rows where the specified field is null or contains whitespace. |
has_max |
Filters rows where the specified field exceeds the given maximum value. |
has_min |
Filters rows where the specified field is below the given minimum value. |
has_std |
Checks if the standard deviation of the specified field exceeds the given value. |
has_mean |
Checks if the mean of the specified field exceeds the given value. |
has_sum |
Checks if the sum of the specified field exceeds the given value. |
has_cardinality |
Checks if the cardinality (number of unique values) of the specified field exceeds the given value. |
has_infogain |
Placeholder for information gain validation (currently uses cardinality). |
has_entropy |
Placeholder for entropy validation (currently uses cardinality). |
satisfies |
Filters rows that do not satisfy the given custom expression. |
validate_date_format |
Filters rows where the specified field does not match the expected date format or is null. |
is_future_date |
Filters rows where the specified date field is after today’s date. |
is_past_date |
Filters rows where the specified date field is before today’s date. |
is_date_between |
Filters rows where the specified date field is not within the given [start,end] range. |
is_date_after |
Filters rows where the specified date field is before the given date. |
is_date_before |
Filters rows where the specified date field is after the given date. |
all_date_checks |
Alias for |
validate |
Validates a DataFrame against a list of rules and returns the original DataFrame with data quality status and a DataFrame of violations. |
__build_rules_df |
Converts a list of rules into a Pandas DataFrame for summarization. |
summarize |
Summarizes the results of data quality checks, including pass rates and statuses. |
validate_schema |
Validates the schema of a DataFrame against an expected schema and returns a boolean result and a list of errors. |
__build_rules_df(rules)
¶
Builds a pandas DataFrame from a list of rule dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rules
|
List[dict]
|
A list of dictionaries where each dictionary represents a rule. Each rule dictionary may contain the following keys: - "field" (str or list): The column(s) the rule applies to. - "check_type" (str): The type of check or rule to apply. - "value" (optional): The value associated with the rule. - "threshold" (optional): A numeric threshold for the rule. Defaults to 1.0 if not provided or invalid. - "execute" (optional): A boolean indicating whether the rule should be executed. Defaults to True. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the processed rules with the following columns: - "column": The column(s) the rule applies to, as a comma-separated string if multiple. - "rule": The type of check or rule. - "value": The value associated with the rule, or an empty string if not provided. - "pass_threshold": The numeric threshold for the rule. |
Notes
- Rules with "execute" set to False are skipped.
- Duplicate rows based on "column", "rule", and "value" are removed from the resulting DataFrame.
Source code in sumeh/engine/pandas_engine.py
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 |
|
__compare_schemas(actual, expected)
¶
Compare two lists of schema definitions and identify discrepancies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
actual
|
List[SchemaDef]
|
The list of actual schema definitions. |
required |
expected
|
List[SchemaDef]
|
The list of expected schema definitions. |
required |
Returns:
Type | Description |
---|---|
bool
|
Tuple[bool, List[Tuple[str, str]]]: A tuple where the first element is a boolean indicating |
List[Tuple[str, str]]
|
whether the schemas match (True if they match, False otherwise), and the second element |
Tuple[bool, List[Tuple[str, str]]]
|
is a list of tuples describing the discrepancies. Each tuple contains: - The field name (str). - A description of the discrepancy (str), such as "missing", "type mismatch", "nullable but expected non-nullable", or "extra column". |
Notes
- A field is considered "missing" if it exists in the expected schema but not in the actual schema.
- A "type mismatch" occurs if the data type of a field in the actual schema does not match the expected data type.
- A field is considered "nullable but expected non-nullable" if it is nullable in the actual schema but not nullable in the expected schema.
- An "extra column" is a field that exists in the actual schema but not in the expected schema.
Source code in sumeh/services/utils.py
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 |
|
__convert_value(value)
¶
Converts the provided value to the appropriate type (date, float, or int).
Depending on the format of the input value, it will be converted to a datetime object, a floating-point number (float), or an integer (int).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The value to be converted, represented as a string. |
required |
Returns:
Type | Description |
---|---|
Union[datetime, float, int]: The converted value, which can be a datetime object, float, or int. |
Raises:
Type | Description |
---|---|
ValueError
|
If the value does not match an expected format. |
Source code in sumeh/services/utils.py
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 |
|
__extract_params(rule)
¶
Source code in sumeh/services/utils.py
38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
__pandas_schema_to_list(df, expected)
¶
Source code in sumeh/engine/pandas_engine.py
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 |
|
__transform_date_format_in_pattern(date_format)
¶
Source code in sumeh/services/utils.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
_day_of_week(df, rule, dow)
¶
Filters a DataFrame to include only rows where the day of the week of a specified datetime field matches the given day.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing a datetime field. |
required |
rule
|
dict
|
A dictionary containing rule parameters. The function expects this to be parsed by |
required |
dow
|
int
|
The day of the week to filter by (0=Monday, 6=Sunday). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only rows where the day of the week matches |
Source code in sumeh/engine/pandas_engine.py
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
|
all_date_checks(df, rule)
¶
Applies all date-related validation checks on the given DataFrame based on the specified rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be validated. |
required |
rule
|
dict
|
A dictionary specifying the validation rules to be applied. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame with the results of the date validation checks. |
Source code in sumeh/engine/pandas_engine.py
904 905 906 907 908 909 910 911 912 913 914 915 |
|
are_complete(df, rule)
¶
Checks for completeness of specified fields in a DataFrame based on a given rule.
This function identifies rows in the DataFrame where any of the specified fields
contain missing values (NaN). It returns a DataFrame containing only the rows
that violate the completeness rule, along with an additional column dq_status
that describes the rule violation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to check for completeness. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the following keys: - fields: A list of column names to check for completeness. - check: A string describing the type of check (e.g., "completeness"). - value: A value associated with the rule (e.g., a threshold or description). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that violate the completeness rule. |
DataFrame
|
The returned DataFrame includes all original columns and an additional column |
DataFrame
|
|
Source code in sumeh/engine/pandas_engine.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
are_unique(df, rule)
¶
Checks for duplicate rows in the specified fields of a DataFrame based on a given rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to check for uniqueness. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - fields: A list of column names to check for uniqueness. - check: A string representing the type of check (e.g., "unique"). - value: A value associated with the rule (e.g., a description or identifier). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the rows that violate the uniqueness rule. An additional column 'dq_status' is added to indicate the rule that was violated in the format "{fields}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
has_cardinality(df, rule)
¶
Checks if the cardinality (number of unique values) of a specified field in the DataFrame exceeds a given value and returns a modified DataFrame if the condition is met.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to check. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The column name in the DataFrame to check. - 'check': The type of check being performed (e.g., 'cardinality'). - 'value': The threshold value for the cardinality. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: - If the cardinality of the specified field exceeds the given value, a copy of the DataFrame is returned with an additional column 'dq_status' indicating the field, check, and value. - If the cardinality does not exceed the value, an empty DataFrame is returned. |
Source code in sumeh/engine/pandas_engine.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
|
has_entropy(df, rule)
¶
Checks if the given DataFrame satisfies a specific rule related to entropy.
This function is a wrapper around the has_cardinality
function, delegating
the rule-checking logic to it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be evaluated. |
required |
rule
|
dict
|
A dictionary containing the rule to be applied. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The resulting DataFrame after applying the rule. |
Source code in sumeh/engine/pandas_engine.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
|
has_infogain(df, rule)
¶
Checks if the given DataFrame satisfies the information gain criteria
defined by the provided rule. This function internally delegates the
operation to the has_cardinality
function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be evaluated. |
required |
rule
|
dict
|
A dictionary defining the rule for information gain. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The resulting DataFrame after applying the rule. |
Source code in sumeh/engine/pandas_engine.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
|
has_max(df, rule)
¶
Identifies rows in a DataFrame where the value in a specified field exceeds a given maximum value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field' (str): The column name to check. - 'check' (str): The type of check being performed (e.g., 'max'). - 'value' (numeric): The maximum allowable value for the specified field. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that violate the rule, with an additional column |
DataFrame
|
'dq_status' indicating the rule violation in the format "field:check:value". |
Source code in sumeh/engine/pandas_engine.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
|
has_mean(df, rule)
¶
Checks if the mean of a specified column in a DataFrame satisfies a given condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to evaluate. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field' (str): The column name to calculate the mean for. - 'check' (str): The condition to check (e.g., 'greater_than'). - 'value' (float): The threshold value to compare the mean against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A copy of the input DataFrame with an additional column 'dq_status' |
DataFrame
|
if the condition is met. The 'dq_status' column contains a string in the format |
DataFrame
|
"{field}:{check}:{value}". If the condition is not met, an empty DataFrame is returned. |
Source code in sumeh/engine/pandas_engine.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
|
has_min(df, rule)
¶
Filters a DataFrame to identify rows where a specified field's value is less than a given threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The column name in the DataFrame to be checked. - 'check': The type of check being performed (e.g., 'min'). - 'value': The threshold value for the check. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing rows that violate the rule, with an additional |
DataFrame
|
column 'dq_status' indicating the field, check type, and threshold value. |
Source code in sumeh/engine/pandas_engine.py
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
|
has_pattern(df, rule)
¶
Checks if the values in a specified column of a DataFrame match a given pattern.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to check. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The column name in the DataFrame to check. - 'check': A descriptive label for the check being performed. - 'pattern': The regex pattern to match against the column values. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that do not match the pattern. An additional column 'dq_status' is added to indicate the field, check, and pattern that caused the violation. |
Source code in sumeh/engine/pandas_engine.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
|
has_std(df, rule)
¶
Checks if the standard deviation of a specified field in the DataFrame exceeds a given value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to evaluate. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The column name in the DataFrame to calculate the standard deviation for. - 'check': A string representing the type of check (not used in the logic but included in the output). - 'value': A numeric threshold to compare the standard deviation against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: - If the standard deviation of the specified field exceeds the given value, returns a copy of the DataFrame with an additional column 'dq_status' indicating the rule details. - If the standard deviation does not exceed the value, returns an empty DataFrame with the same structure as the input. |
Source code in sumeh/engine/pandas_engine.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
|
has_sum(df, rule)
¶
Checks if the sum of values in a specified column of a DataFrame exceeds a given threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field' (str): The column name to calculate the sum for. - 'check' (str): A descriptive label for the check (used in the output). - 'value' (float): The threshold value to compare the sum against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: - If the sum of the specified column exceeds the threshold, returns a copy of the input DataFrame with an additional column 'dq_status' indicating the rule that was applied. - If the sum does not exceed the threshold, returns an empty DataFrame with the same structure as the input. |
Source code in sumeh/engine/pandas_engine.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
|
is_between(df, rule)
¶
Filters a DataFrame to identify rows where a specified field's values are not within a given range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The column name in the DataFrame to check. - 'check': A descriptive label for the check being performed. - 'value': A string representation of the range in the format '[lo, hi]'. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that violate the range condition. An additional column 'dq_status' is added to indicate the rule violation in the format 'field:check:value'. |
Source code in sumeh/engine/pandas_engine.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
|
is_complete(df, rule)
¶
Checks for missing values in a specified field of a DataFrame based on a given rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to check for completeness. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The name of the field/column to check for missing values. - 'check': The type of check being performed (not used in this function). - 'value': Additional value associated with the rule (not used in this function). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows where the specified field has missing values. An additional column 'dq_status' is added to indicate the rule that was violated. |
Source code in sumeh/engine/pandas_engine.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
is_contained_in(df, rule)
¶
Filters a DataFrame to identify rows where the values in a specified field are not contained within a given set of values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the following keys: - 'field': The column name in the DataFrame to check. - 'check': A descriptive string for the check being performed. - 'value': A list or string representation of the allowed values. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows from the input DataFrame that do not meet the rule criteria. An additional column 'dq_status' is added to indicate the rule violation in the format "field:check:value". |
Source code in sumeh/engine/pandas_engine.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
is_date_after(df, rule)
¶
Filters a DataFrame to return rows where a specified date field is earlier than a given target date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include:
- field (str): The name of the column in the DataFrame to check.
- check (str): A descriptive label for the check being performed.
- date_str (str): The target date as a string in a format parsable by |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows where the date in the specified field is earlier |
DataFrame
|
than the target date. An additional column |
DataFrame
|
was violated in the format "{field}:{check}:{date_str}". |
Source code in sumeh/engine/pandas_engine.py
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
|
is_date_before(df, rule)
¶
Filters a DataFrame to identify rows where a date field is after a specified target date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include:
- field (str): The name of the column in the DataFrame containing date values.
- check (str): A descriptive label for the check being performed.
- date_str (str): The target date as a string in a format parsable by |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows where the date in the specified field is after |
DataFrame
|
the target date. An additional column |
DataFrame
|
violated in the format "{field}:{check}:{date_str}". |
Source code in sumeh/engine/pandas_engine.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
|
is_date_between(df, rule)
¶
Filters rows in a DataFrame where the values in a specified date column are not within a given date range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the following: - field: The name of the column to check. - check: A string representing the type of check (used for status annotation). - raw: A string representing the date range in the format '[start_date, end_date]'. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the rows where the date values in the specified column are outside the given range. An additional column 'dq_status' is added to indicate the rule that was violated. |
Source code in sumeh/engine/pandas_engine.py
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 |
|
is_equal(df, rule)
¶
Filters a DataFrame to identify rows where the value in a specified field does not match a given value, and annotates these rows with a data quality status.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The column name in the DataFrame to check. - 'check': A string describing the check being performed (e.g., "is_equal"). - 'value': The value to compare against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that do not satisfy the equality check. |
DataFrame
|
An additional column 'dq_status' is added to indicate the data quality status |
DataFrame
|
in the format "{field}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
|
is_equal_than(df, rule)
¶
Compares the values in a DataFrame against a specified rule and returns the result.
This function acts as a wrapper for the is_equal
function, passing the given
DataFrame and rule to it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The DataFrame to be evaluated. |
required |
rule
|
dict
|
A dictionary containing the comparison rule. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame indicating the result of the comparison. |
Source code in sumeh/engine/pandas_engine.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
is_future_date(df, rule)
¶
Identifies rows in a DataFrame where the date in a specified field is in the future.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the field name to check and the check type. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing only the rows where the date in the specified field is in the future. An additional column 'dq_status' is added to indicate the field, check type, and the current date in ISO format. |
Source code in sumeh/engine/pandas_engine.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
|
is_greater_or_equal_than(df, rule)
¶
Filters a DataFrame to include only rows where the value in a specified field is greater than or equal to a given threshold. Adds a 'dq_status' column to indicate the rule applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field' (str): The column name to apply the rule on. - 'check' (str): The type of check being performed (e.g., 'greater_or_equal'). - 'value' (numeric): The threshold value for the comparison. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing only the rows that satisfy the rule, |
DataFrame
|
with an additional 'dq_status' column describing the rule applied. |
Source code in sumeh/engine/pandas_engine.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
is_greater_than(df, rule)
¶
Filters a DataFrame to return rows where a specified field's value is greater than a given threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field' (str): The column name in the DataFrame to be checked. - 'check' (str): The type of check being performed (e.g., 'greater_than'). - 'value' (numeric): The threshold value to compare against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing rows where the specified field's value is greater than the given threshold. An additional column 'dq_status' is added to indicate the rule applied in the format "field:check:value". |
Source code in sumeh/engine/pandas_engine.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
is_in(df, rule)
¶
Checks if the values in a DataFrame satisfy a given rule by delegating
the operation to the is_contained_in
function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be evaluated. |
required |
rule
|
dict
|
A dictionary defining the rule to check against the DataFrame. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame indicating whether each element satisfies the rule. |
Source code in sumeh/engine/pandas_engine.py
427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
is_in_billions(df, rule)
¶
Filters a DataFrame to include only rows where the specified field's value is greater than or equal to one billion, and adds a data quality status column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to filter. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - field (str): The column name to check. - check (str): The type of check being performed (used for status annotation). - value (any): The value associated with the rule (used for status annotation). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing rows where the specified field's |
DataFrame
|
value is greater than or equal to one billion. Includes an additional |
DataFrame
|
column |
Source code in sumeh/engine/pandas_engine.py
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 |
|
is_in_millions(df, rule)
¶
Filters rows in the DataFrame where the specified field's value is greater than or equal to one million and adds a "dq_status" column with a formatted string indicating the rule applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to filter. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include: - field (str): The column name to check. - check (str): The type of check being performed (e.g., "greater_than"). - value (any): The value associated with the rule (not used in this function). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing rows where the specified field's value is >= 1,000,000. Includes an additional "dq_status" column with the rule details. |
Source code in sumeh/engine/pandas_engine.py
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 |
|
is_legit(df, rule)
¶
Validates a DataFrame against a specified rule and identifies rows that violate the rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to validate. |
required |
rule
|
dict
|
A dictionary containing the validation rule. It is expected to have keys that define the field to check, the type of check, and the value to validate against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that violate the rule. An additional column 'dq_status' is added to indicate the field, check, and value that caused the violation in the format "{field}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
is_less_or_equal_than(df, rule)
¶
Filters rows in a DataFrame where the value in a specified field is less than or equal to a given value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field' (str): The column name in the DataFrame to apply the rule on. - 'check' (str): A descriptive label for the check being performed. - 'value' (numeric): The threshold value to compare against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing only the rows that satisfy the condition. An additional column 'dq_status' is added to indicate the rule applied in the format "{field}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
is_less_than(df, rule)
¶
Filters a DataFrame to return rows where a specified field's value is less than a given threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field' (str): The column name in the DataFrame to be checked. - 'check' (str): A descriptive string for the check (e.g., "less_than"). - 'value' (numeric): The threshold value to compare against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing only the rows where the specified field's value |
DataFrame
|
is less than the given threshold. An additional column 'dq_status' is added to indicate |
DataFrame
|
the rule applied in the format "field:check:value". |
Source code in sumeh/engine/pandas_engine.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
is_negative(df, rule)
¶
Filters a DataFrame to identify rows where a specified field does not satisfy a "negative" condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include: - 'field': The column name in the DataFrame to check. - 'check': The type of check being performed (e.g., "negative"). - 'value': Additional value associated with the rule (not used in this function). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing rows where the specified field is non-negative (>= 0). An additional column 'dq_status' is added to indicate the rule violation in the format "{field}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
is_on_friday(df, rule)
¶
Filters the rows of a DataFrame based on whether a specific date column corresponds to a Friday.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rules or parameters for filtering. It should specify the column to check for the day of the week. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only the rows where the specified date column corresponds to a Friday. |
Source code in sumeh/engine/pandas_engine.py
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
|
is_on_monday(df, rule)
¶
Filters the rows of a DataFrame based on whether a specific date column corresponds to a Monday.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be filtered. |
required |
rule
|
dict
|
A dictionary containing the filtering rules, including the column to check. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only the rows where the specified date column corresponds to a Monday. |
Source code in sumeh/engine/pandas_engine.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
|
is_on_saturday(df, rule)
¶
Filters a DataFrame to include only rows where the date corresponds to a Saturday.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing date information. |
required |
rule
|
dict
|
A dictionary containing rules or parameters for filtering. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only rows where the date is a Saturday. |
Source code in sumeh/engine/pandas_engine.py
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 |
|
is_on_sunday(df, rule)
¶
Determines whether the dates in a given DataFrame fall on a Sunday.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing date-related data. |
required |
rule
|
dict
|
A dictionary containing rules or parameters for the operation. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame indicating whether each date falls on a Sunday. |
Source code in sumeh/engine/pandas_engine.py
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
|
is_on_thursday(df, rule)
¶
Filters the rows of a DataFrame based on whether a date column corresponds to a Thursday.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be filtered. |
required |
rule
|
dict
|
A dictionary containing the filtering rules, including the column to check. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only the rows where the specified date column corresponds to a Thursday. |
Source code in sumeh/engine/pandas_engine.py
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 |
|
is_on_tuesday(df, rule)
¶
Filters the rows of a DataFrame based on whether a specific date column corresponds to a Tuesday.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be filtered. |
required |
rule
|
dict
|
A dictionary containing the filtering rules, including the column to check. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only the rows where the specified date column corresponds to a Tuesday. |
Source code in sumeh/engine/pandas_engine.py
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
|
is_on_wednesday(df, rule)
¶
Filters the rows of a DataFrame based on whether a date column corresponds to Wednesday.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule configuration. It is expected to specify the column to evaluate. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only the rows where the specified date column corresponds to Wednesday. |
Source code in sumeh/engine/pandas_engine.py
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 |
|
is_on_weekday(df, rule)
¶
Filters a DataFrame to include only rows where the specified date field falls on a weekday (Monday to Friday) and adds a "dq_status" column indicating the rule applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - field (str): The name of the date column to check. - check (str): A descriptive string for the check being performed. - value (str): A value associated with the rule for documentation purposes. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only rows where the specified date field |
DataFrame
|
falls on a weekday, with an additional "dq_status" column describing the rule applied. |
Source code in sumeh/engine/pandas_engine.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 |
|
is_on_weekend(df, rule)
¶
Filters a DataFrame to include only rows where the specified date field falls on a weekend (Saturday or Sunday) and adds a "dq_status" column indicating the rule applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include: - field (str): The name of the date column to check. - check (str): A descriptive string for the type of check being performed. - value (str): A value associated with the rule for documentation purposes. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing only the rows where the specified date field |
DataFrame
|
falls on a weekend. Includes an additional "dq_status" column with the rule details. |
Source code in sumeh/engine/pandas_engine.py
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 |
|
is_past_date(df, rule)
¶
Identifies rows in a DataFrame where the date in a specified column is in the past.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the field name to check and the check type. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the rows where the date in the specified column is earlier than the current date. An additional column 'dq_status' is added to indicate the field, check type, and the current date. |
Notes
- The function uses
pd.to_datetime
to convert the specified column to datetime format. Any invalid date entries will be coerced to NaT (Not a Time). - Rows with invalid or missing dates are excluded from the result.
Source code in sumeh/engine/pandas_engine.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
|
is_positive(df, rule)
¶
Identifies rows in a DataFrame where the specified field contains negative values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be checked. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include: - 'field': The column name in the DataFrame to check. - 'check': A descriptive label for the type of check being performed. - 'value': A value associated with the rule (not directly used in this function). |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing only the rows where the specified field has negative values. An additional column 'dq_status' is added to indicate the rule violation in the format "{field}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
is_t_minus_2(df, rule)
¶
Filters a DataFrame to include only rows where the specified date field matches the date two days prior to the current date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to filter. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the field name, check type, and value. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only the rows where the |
DataFrame
|
specified date field matches the target date (two days prior). An |
DataFrame
|
additional column "dq_status" is added to indicate the rule applied. |
Source code in sumeh/engine/pandas_engine.py
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 |
|
is_t_minus_3(df, rule)
¶
Filters a DataFrame to include only rows where the specified date field matches the date three days prior to the current date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to filter. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. The rule should include the field to check, the type of check, and the value. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only the rows where the |
DataFrame
|
specified date field matches the target date (three days prior). An |
DataFrame
|
additional column "dq_status" is added to indicate the rule applied. |
Source code in sumeh/engine/pandas_engine.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
|
is_today(df, rule)
¶
Filters a DataFrame to include only rows where the specified date field matches today's date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to filter. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the field name, a check operation, and a value. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame containing only the rows where the specified date field matches today's date. An additional column "dq_status" is added to indicate the rule applied in the format "{field}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
|
is_unique(df, rule)
¶
Checks for duplicate values in a specified field of a DataFrame based on a rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to check for duplicates. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to include the field to check, the type of check, and a value. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the rows with duplicate values in the specified field. An additional column 'dq_status' is added to indicate the field, check type, and value associated with the rule. |
Source code in sumeh/engine/pandas_engine.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
is_yesterday(df, rule)
¶
Filters a DataFrame to include only rows where the specified date field matches yesterday's date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to filter. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It is expected to have
keys that allow |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A filtered DataFrame containing only rows where the specified date field
matches yesterday's date. An additional column |
Source code in sumeh/engine/pandas_engine.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
|
not_contained_in(df, rule)
¶
Filters a DataFrame to return rows where the specified field contains values that are not allowed according to the provided rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be filtered. |
required |
rule
|
dict
|
A dictionary containing the rule parameters. It should include: - 'field': The column name in the DataFrame to check. - 'check': The type of check being performed (used for status annotation). - 'value': A list or string representation of values that are not allowed. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that violate the rule. An additional |
DataFrame
|
column 'dq_status' is added to indicate the rule violation in the format |
DataFrame
|
"{field}:{check}:{value}". |
Source code in sumeh/engine/pandas_engine.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
not_in(df, rule)
¶
Filters a DataFrame by excluding rows that match the specified rule.
This function is a wrapper around the not_contained_in
function,
which performs the actual filtering logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be filtered. |
required |
rule
|
dict
|
A dictionary specifying the filtering criteria. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A new DataFrame with rows that do not match the rule. |
Source code in sumeh/engine/pandas_engine.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
|
satisfies(df, rule)
¶
Filters a DataFrame based on a rule and returns rows that do not satisfy the rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to be evaluated. |
required |
rule
|
dict
|
A dictionary containing the rule to be applied. It is expected
to contain parameters that can be extracted using the |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that do not satisfy the rule. An additional |
DataFrame
|
column |
Source code in sumeh/engine/pandas_engine.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 |
|
summarize(qc_df, rules, total_rows)
¶
Summarizes quality check results for a given DataFrame based on specified rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qc_df
|
DataFrame
|
The input DataFrame containing a 'dq_status' column with quality check results in the format 'column:rule:value', separated by semicolons. |
required |
rules
|
list[dict]
|
A list of dictionaries representing the quality check rules. Each dictionary should define the 'column', 'rule', 'value', and 'pass_threshold'. |
required |
total_rows
|
int
|
The total number of rows in the original dataset. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame summarizing the quality check results with the following columns: - 'id': A unique identifier for each rule. - 'timestamp': The timestamp of the summary generation. - 'check': The type of check performed (e.g., 'Quality Check'). - 'level': The severity level of the check (e.g., 'WARNING'). - 'column': The column name associated with the rule. - 'rule': The rule being checked. - 'value': The value associated with the rule. - 'rows': The total number of rows in the dataset. - 'violations': The number of rows that violated the rule. - 'pass_rate': The proportion of rows that passed the rule. - 'pass_threshold': The threshold for passing the rule. - 'status': The status of the rule ('PASS' or 'FAIL') based on the pass rate. |
Notes
- The function calculates the number of violations for each rule and merges it with the provided rules to compute the pass rate and status.
- The 'timestamp' column is set to the current time with seconds and microseconds set to zero.
Source code in sumeh/engine/pandas_engine.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 |
|
validate(df, rules)
¶
Validates a pandas DataFrame against a set of rules and returns the processed DataFrame along with a DataFrame containing validation violations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame to validate. |
required |
rules
|
list[dict]
|
A list of dictionaries, where each dictionary represents a validation rule. Each rule should contain the following keys: - 'check_type' (str): The type of validation to perform. This should correspond to a function name available in the global scope. Special cases include 'is_primary_key' and 'is_composite_key', which map to 'is_unique' and 'are_unique', respectively. - 'execute' (bool, optional): Whether to execute the rule. Defaults to True. |
required |
Returns:
Type | Description |
---|---|
Tuple[DataFrame, DataFrame]
|
Tuple[pd.DataFrame, pd.DataFrame]: A tuple containing: - The processed DataFrame with validation statuses merged. - A DataFrame containing rows that violated the validation rules. |
Notes
- The input DataFrame is copied and reset to ensure the original data is not modified.
- An '_id' column is temporarily added to track row indices during validation.
- If a rule's 'check_type' does not correspond to a known function, a warning is issued.
- The 'dq_status' column in the violations DataFrame summarizes validation issues for each row.
Source code in sumeh/engine/pandas_engine.py
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 |
|
validate_date_format(df, rule)
¶
Validates the date format of a specified field in a DataFrame against a given format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing the data to validate. |
required |
rule
|
dict
|
A dictionary containing the validation rule. It should include: - 'field': The name of the column to validate. - 'check': A description or identifier for the validation check. - 'fmt': The expected date format to validate against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing rows that violate the date format rule. An additional column 'dq_status' is added to indicate the validation status in the format "{field}:{check}:{fmt}". |
Source code in sumeh/engine/pandas_engine.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 |
|
validate_schema(df, expected)
¶
Validates the schema of a given DataFrame against an expected schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
The DataFrame whose schema needs to be validated. |
required | |
expected
|
The expected schema, represented as a list of tuples where each tuple contains the column name and its data type. |
required |
Returns:
Type | Description |
---|---|
Tuple[bool, List[Tuple[str, str]]]
|
Tuple[bool, List[Tuple[str, str]]]: A tuple containing: - A boolean indicating whether the schema matches the expected schema. - A list of tuples representing the errors, where each tuple contains the column name and a description of the mismatch. |
Source code in sumeh/engine/pandas_engine.py
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 |
|