Skip to content

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.

Example
>>> df = pd.DataFrame({'status': ['Active', 'active', 'Inactive', 'ACTIVE']})
>>> warnings = check_case_consistency(df)
>>> print(warnings[0])

[Case Consistency] Column 'status': mixed case detected (e.g., 'Active', 'active', 'ACTIVE')

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.

Example
>>> df = pd.DataFrame({'a': [1, 1, 1]})
>>> warnings = check_constant_columns(df)
>>> print(warnings[0])

[Constant Column] Column 'a' has only one unique value: 1.

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:

>>> df = pd.DataFrame({'a': [1, 2, 3, 4, 5], 'b': [2, 4, 6, 8, 10], 'c': [5, 4, 3, 2, 1]})
>>> warnings = check_correlation_warnings(df, threshold=0.9)
>>> print(warnings[0])

[High Correlation] Columns 'a' and 'b' are 100.0% correlated.

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.

Example
>>> df = pd.DataFrame({'age': ['25', '30', '35']})
>>> warnings = check_data_type_consistency(df)
>>> print(warnings[0])

[Type Warning] Column 'age' is stored as object, consider numeric type.

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.

Example
>>> df = pd.DataFrame({'date': ['2020-01-01', '01/02/2020', '2020-03-01']})
>>> warnings = check_date_format_consistency(df)
>>> print(warnings[0])

[Date Format Consistency] Column 'date' has 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.

Example
>>> df = pd.DataFrame({'event_date': pd.to_datetime(['1900-01-01', '2000-01-01', '1950-06-15'])})
>>> warnings = check_date_range_anomalies(df, threshold_years=80)
>>> print(warnings[0])

[Date Range Anomalies] Column 'event_date': date range spans 100.0 years (1900-01-01 to 2000-01-01).

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.

Example
>>> df = pd.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3], 'c': [4, 5, 6]})
>>> warnings = check_duplicate_columns(df)
>>> print(warnings[0])

[Duplicate Columns] Columns 'a' and 'b' are identical.

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.

Example
>>> df = pd.DataFrame({'a': [1, 2, 2], 'b': ['x', 'y', 'y']})
>>> warnings = check_duplicate_rows(df)
>>> print(warnings[0])

[Duplicate Rows] Found 1 duplicate row(s) at index: 2

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.

Example
>>> df = pd.DataFrame({'birth_date': pd.to_datetime(['1990-01-01', '2050-01-01', '1985-06-15'])})
>>> warnings = check_future_dates(df)
>>> print(warnings[0])

[Future Dates] Column 'birth_date' has 1 date(s) in the future compared to 2024-06-01.

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.

Example
>>> df = pd.DataFrame({'age': [25, None, 30, None], 'income': [50000, None, 60000, None]})
>>> warnings = check_missing_patterns(df, threshold=0.8)
>>> print(warnings[0])

[Missing Patterns] Columns 'age' and 'income' identical missing rows (likely related).

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.

Example
>>> df = pd.DataFrame({'a': [1, 2, None], 'b': ['x', 'y', 'z']})
>>> warnings = check_missing_values(df)
>>> print(warnings[0])

[Missing Values] Column 'a': 1 missing values (33.3%)

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.

Example
>>> df = pd.DataFrame({'a': [1, 'two', 3], 'b': [1.0, 2.0, 3.0]})
>>> warnings = check_mixed_types(df)
>>> print(warnings[0])

[Mixed Types] Column 'a' has mixed types: int (66%), str (33%)

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.

Example
>>> df = pd.DataFrame({'age': [25, -30, 35], 'income': [50000, 60000, -70000]})
>>> warnings = check_negative_values(df, columns=['age'])
>>> print(warnings[0])

[Negative Values] Column 'age' has 1 negative value(s).

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:

>>> df = pd.DataFrame({'a': [1, 2, 3, 100, 5]})
>>> warnings = check_outliers(df)
>>> print(warnings[0])

[Outliers] Column 'a': 1 potential outlier(s) detected (iqr method).

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.

Example
>>> df = pd.DataFrame({'category': ['A'] * 98 + ['B', 'C']})
>>> warnings = check_rare_categories(df, threshold=0.02)
>>> print(warnings[0])

[Rare Categories] Column 'category': 2 categories appear <2.0% of the time.

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 df. Value: Either a parent DataFrame (assumes the first column is the referenced column), or a tuple of (parent_df, parent_column_name) for explicit column reference.

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.

Example
>>> df = pd.DataFrame({'a': [1, 2, 3, 100, 5]})
>>> warnings = check_skewness(df, threshold=1.0)
>>> print(warnings[0])

[Skewness] Column 'a' is highly right-skewed (skewness=2.5). Consider log transformation.

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.

Example
>>> df = pd.DataFrame({'name': ['Alice', 'Bob™', 'Charlie•']})
>>> warnings = check_special_characters(df)
>>> print(warnings[0])

[Special Characters] Column 'name': 66.7% of values contain special or non-standard 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.

Example
>>> df = pd.DataFrame({'a': [1, 2, 3, 4, 5]})
>>> warnings = check_unique_columns(df, threshold=0.8)
>>> print(warnings[0])

[Unique Column] Column 'a' is 100.0% unique

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.

Example
>>> df = pd.DataFrame({'a': [' x', 'y ', ' z ']})
>>> warnings = check_whitespace(df)
>>> print(warnings[0])

[Whitespace] Column 'a' has 3 value(s) 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.

Example
>>> df = pd.DataFrame({'purchases': [0, 0, 0, 0, 0, 100, 200]})
>>> warnings = check_zero_inflation(df, threshold=0.5)
>>> print(warnings[0])

[Zero Inflation] Column 'purchases': 71.4% of values are zero