Checks Module
The checks module contains all data quality validation functions.
Overview
Each check function:
- Accepts a pandas DataFrame
- Returns a list of warning strings
- Returns empty list
[]if no issues found - Can be called directly or via the
.lint.report()accessor
from lintdata import checks
import pandas as pd
df = pd.DataFrame({"age": [25, 30, None]})
warnings = checks.check_missing_values(df)
# Returns: ["[Missing Values] Column 'age': 1 missing values (33.3%)"]
Available Checks
check_cardinality(df, high_threshold=50, low_threshold=2)
Check for columns with unusually high or low cardinality.
Identifies categorical columns with too many unique valies (high cardinality, potentially an ID column) or too few unique values (lower cardinality, potentially a constant or near-constant column (boolean-like)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
high_threshold
|
int
|
The maximum number of unique values for a column to be considered low cardinality. Defaults to 50. |
50
|
low_threshold
|
int
|
The minimum number of unique values for a column to be considered high cardinality. Defaults to 2. |
2
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with unusual cardinality. |
Example
>>> df = pd.DataFrame({'id': range(100), 'status': ['active'] * 100})
>>> warnings = check_cardinality(df, high_threshold=80, low_threshold=5)
>>> print(warnings[0])
[High Cardinality] Column 'id' has 100 unique values (100.0% unique)
>>> print(warnings[1])
[Low Cardinality] Column 'status' has only 1 unique value.
check_case_consistency(df, min_unique=2)
Check for inconsistent casing in string columns.
Detects columns where the same logical value appears with different casing (e.g., "Active", "active", "ACTIVE"). This is common in categorical data and can cause issues in analysis and grouping operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to analyse |
required |
min_unique
|
int
|
Minimum number of unique values for a column to be checked. Columns with fewer unique values are skipped as they're likely boolean-like. Defaults to 2. |
2
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with inconsistent casing. |
check_constant_columns(df)
Check for columns where all values are the same (zero variance).
Identifies columns with only one unique value (excluding NaN), which are often redundant for analysin/modelling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for constant columns found. |
check_correlation_warnings(df, threshold=0.95)
Check correlation between numeric columns.
Identifies pairs of numeric columns that have a high correlation (above the specified threshold), which may indicate redundancy or multicollinearity issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
threshold
|
float
|
Correlation threshold above which warnings are generated. Defaults to 0.95. |
0.95
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the threshold is not between 0 and 1. |
Returns: List[str]: A list of warning messages for highly correlated column pairs. Example:
check_data_type_consistency(df)
Check if column data types match expected patterns based on column names.
Uses heuristics to identify columns that may have incorrect data types based on commin naming patterns. For example, "columns" with 'date' in the name should be datetime, 'age' or 'count' should be numeric, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for data type inconsistencies. |
check_date_format_consistency(df)
Check for inconsistent date formats in string columns.
Attemps to detect columns that contain dates in multiple formats (e.g., 'YYYY-MM-DD' and 'DD/MM/YYYY' mixed together).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with inconsistent date formats. |
check_date_range_anomalies(df, columns=None, threshold_years=50)
Check for columns where the range between the minimum and maximum dates is unusually large.
This funciton identifies date columns where the span between the earliest and latest dates exceeds a specified threshold (default: 50 years). Such anomalies may indicate data entry errors, incorrect date parsing, or unexpected data distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
columns
|
Optional[List[str]]
|
Specific columns to check. Defaults to None. |
None
|
threshold_years
|
float
|
Maximum acceptable date range in years. Columns with date ranges exceeding will be flagged. Defaults to 50. |
50
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for date range anomalies. |
check_duplicate_columns(df)
Check for columns with identical values (reduntant columns).
Identifies pairs of columns that contain exactly the same data, which are often redundant and can be removed to simplify the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for duplicate columns pairs. |
check_duplicate_rows(df)
Check for duplicate rows in the DataFrame
A row is considered a duplicate if all its values match another row in the DataFrame. The first occurrence is not counted as a duplicate. Indices start at 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for duplicate rows with specific indices. |
check_future_dates(df, columns=None, reference_date=None)
Check for dates that occur in the future.
Identifies date values that are later than the reference date (default: today), which may indicate data entry errors or incorrect date parsing for historical data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
columns
|
Optional[List[str]]
|
Specific columns to check. If None, checks all datetime columns and columns with 'date' in the name. Defaults to None. |
None
|
reference_date
|
Optional[str]
|
The reference date to compare against. If None, uses today's date. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If reference_date is provided but not in ISO format (YYYY-MM-DD). |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for future dates. |
check_missing_patterns(df, threshold=0.9)
Detects patterns in missing data across columns.
Identifies when multiple columns have missing values in the same rows, which may indicate systematic missingness (e.g., related fields that are filled out together or not at all.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
threshold
|
float
|
The threshold for detecting missing patterns. Defaults to 0.9. |
0.9
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with detected missing patterns. |
check_missing_values(df)
Check for missing values in the DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages describing missing values found. |
check_mixed_types(df)
Check for columns containing mixed data types.
Detects columns where values have different Python types (e.g., integers mixed with strings). Reports the specific types found and their proportions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for mixed data types found with specific type breakdowns. |
check_negative_values(df, columns=None)
Check for negative values in columns that shouldn't have them.
Detects negative values in numerical columns. Optionally specify which columns to check, otherwise all numerical columns are checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
columns
|
Optional[List[str]]
|
Specific columns to check. Defaults to None. If None, all numeric columns are checked. |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with negative values. |
check_outliers(df, method='iqr', threshold=1.5)
Check for outliers using different methods.
Provides a threshold value that sets trigger for outliers. Currently supports IQR method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
method
|
Optional[str]
|
The outlier detection method to use. Defaults to "iqr". |
'iqr'
|
threshold
|
Optional[float]
|
The threshold for detecting outliers. Defaults to 1.5. |
1.5
|
Raises:
| Type | Description |
|---|---|
ValueError(Method)
|
If the method is not supported. |
ValueError(Threshold)
|
If the threshold is not a positive number. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with detected outliers. |
Example:
check_rare_categories(df, threshold=0.01)
Check for categories that appear very infrequently.
Identifies categorical valaues that appear less than the threshold percentage of times. These rare categories can cause issues in modelling and analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
threshold
|
float
|
The minimum proportion for a category to not be considered rare. Defaults to 0.01 (1%). |
0.01
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the threshold is not between 0 and 1. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with rare categories. |
check_referential_integrity(df, foreign_keys)
Check if foreing key values exist in their referenced parent tables.
This function validates referential integrity by checking whether values in specified foreign key columns exist in their corresponding parent tables. This is essential for multi-table data validation and ensures consistency across related datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The child DataFrame containing foreign key column(s) to validate. |
required |
foreign_keys
|
Dict[str, Union[DataFrame, Tuple[DataFrame, str]]]
|
Dictionary mapping foreign key column names to their parent tables.
Key: Name of the foreign key column in |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a foreign key column or parent column is not found in the child DataFrame or parent DataFrame respectively. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for foreign key violations. |
Notes
- Null values in foreign key columns are ignored.
- Only checks for existence; does not validate other constraints (e.g., cascading deletes).
Example
>>> users = pd.DataFrame({'user_id': [1, 2, 3]})
>>> orders = pd.DataFrame({'order_id': [101, 102, 103], 'user_id': [1, 2, 4]})
>>> warnings = check_referential_integrity(orders, {'user_id': users})
>>> print(warnings[0])
[Referential Integrity] Column 'user_id': 1 values not found in parent column 'user_id' (33.3% of non-null values).
check_skewness(df, threshold=1.0)
Check for skewness in numeric columns.
Detects if a column is right or left leaning in variance. Recommends if a log transformation might be required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check |
required |
threshold
|
float
|
The threshold for detecting threshold. Defaults to 1.0. |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the threshold is not a positive number. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for skewed columns. |
check_special_characters(df, threshold=0.1)
Check for unusual or potentially problematic special characters in text columns.
Detects columns containing special characters that may indicate encoding issues, copy-paste errors, or data corruption. Looks for non-ASCII characters, control characters, and common mis-encoded symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
threshold
|
float
|
The proportion of special characters allowed before raising a warning. Defaults to 0.1. |
0.1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the threshold is not between 0 and 1. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for special characters. |
check_string_length_outliers(df, threshold=3.0)
Check for strings that are significantly longer or shorter than others.
Detects string values with unusual lengths compared to other values in the same column, which may indicate data entry errors or data quality issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
threshold
|
float
|
For small samples (n<10), this is a ratio multiplier. For larger samples, this is the number of standard deviations. Defaults to 3.0. |
3.0
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with string length outliers. |
Example
>>> df = pd.DataFrame({'email': ['[email protected]', '[email protected]', 'x' * 100 + '@example.com']})
>>> warnings = check_string_length_outliers(df)
>>> print(warnings[0])
[String Length Outliers] Column 'email' has 1 value(s) with unusual length
check_unique_columns(df, threshold=0.95)
Check for columns with a high proportion of unique values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
threshold
|
float
|
The unique value proportion threshold. Defaults to 0.95. |
0.95
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns exceeding the unique value threshold. |
check_whitespace(df)
Detects string values that have leading or trailing spaces, which can cause issues in data analysis and matching operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with leading or trailing whitespace. |
check_zero_inflation(df, threshold=0.5)
Check for columns with an excessive proportion of zero values.
Detects numerical columns where zeros make up more than the specified threshold percentage of values. This can indicate data collection issues, default values, or sparse data that may need special handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to check. |
required |
threshold
|
float
|
The minimum proportion of zeros to flag (0-1). Defaults to 0.5 (50%). |
0.5
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the threshold is not between 0 and 1. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of warning messages for columns with excessive zero values. |