LintAccessor
The LintAccessor class provides the .lint accessor for pandas DataFrames.
LintAccessor(pandas_obj)
An Accessor for pandas DataFrames to run data quality checks.
Source code in src/lintdata/accessor.py
list_custom_checks()
List all registered custom check names.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Names of registered custom checks. |
register_check(check_func, name=None)
Register a custom check function.
Custom check functions should accept a DataFrame as the first argument and return a List[str] of warning messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
check_func
|
Any
|
Function that takes a DataFrame and returns List[str] of warnings. |
required |
name
|
Optional[str]
|
Name to register the check under. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If check function is not callable or name already registered. |
Example
Source code in src/lintdata/accessor.py
report(checks_to_run=None, outlier_threshold=1.5, skewness_threshold=1.0, rare_category_threshold=0.01, unique_column_threshold=0.95, cardinality_high_threshold=50, cardinality_low_threshold=2, string_length_threshold=3.0, negative_value_columns=None, zero_inflation_threshold=0.5, future_date_columns=None, future_date_reference=None, special_chars_threshold=0.1, threshold_years=50, correlation_threshold=0.95, foreign_key_mappings=None, report_format='text', output=None, return_dict=False, n_jobs=1, backend='multiprocessing', min_checks_for_parallel=3)
Generate a comprehensive quality report for the DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checks_to_run
|
Optional[Union[List[str], str]]
|
Specific checks to run. Options: 'missing', 'duplicates', 'mixed_types', 'whitespace', 'constant', 'unique', 'outliers', 'missing_patterns', 'case', 'cardinality', 'skewness', 'duplicate_columns', 'type_consistency', 'negative', 'rare_categories', 'date_format', 'string_length', 'zero_inflation', 'future_dates', 'special_chars', 'date_anomalies', 'correlation', 'foreign_keys'. Use 'all' to run all checks. Defaults to None. |
None
|
outlier_threshold
|
float
|
Outlier detection threshold using the IQR method. Defaults to 1.5. |
1.5
|
skewness_threshold
|
float
|
Threshold for skewness detection. Defaults to 1.0. |
1.0
|
rare_category_threshold
|
float
|
Minimum proportion for rare categories. Defaults to 0.01. |
0.01
|
unique_column_threshold
|
float
|
Threshold for identifying unique columns. Defaults to 0.95. |
0.95
|
cardinality_high_threshold
|
int
|
High cardinality threshold. Defaults to 50. |
50
|
cardinality_low_threshold
|
int
|
Low cardinality threshold. Defaults to 2. |
2
|
string_length_threshold
|
float
|
Threshold for identifying string length outliers. Defaults to 3.0. |
3.0
|
negative_value_columns
|
Optional[List[str]]
|
Specific columns to check for negative values. Defaults to None. |
None
|
zero_inflation_threshold
|
float
|
Minimum proportion of zeros to flag. Defaults to 0.5. |
0.5
|
future_date_columns
|
Optional[List[str]]
|
Specific columns to check for future dates. Defaults to None. |
None
|
future_date_reference
|
Optional[str]
|
Reference date for future date check (YYYY-MM-DD). Defaults to None (today). |
None
|
special_chars_threshold
|
float
|
Minimum proportion of values with special characters. Defaults to 0.1. |
0.1
|
threshold_years
|
float
|
Maximum acceptable date range in years. Columns with date ranges exceeding will be flagged. Defaults to 50. |
50
|
correlation_threshold
|
float
|
Threshold for flagging highly correlated columns. Defaults to 0.95. |
0.95
|
foreign_key_mappings
|
Optional[Dict[str, Union[DataFrame, Tuple[DataFrame, str]]]]
|
Mappings for referential integrity checks. Key: foreign key column in the DataFrame. Value: either parent DataFrame (assumes first column is referenced) or tuple of (parent_df, parent_column_name). Defaults to None. |
None
|
report_format
|
str
|
Output format. Options: 'text', 'html', 'json', 'csv'. Defaults to 'text'. |
'text'
|
output
|
Optional[str]
|
File path to save the report. If None, returns as string. Defaults to None. |
None
|
return_dict
|
bool
|
If True, returns structured dictionary instead of formatted string. Defaults to False. |
False
|
n_jobs
|
int
|
Number of parallel workers. -1: Use all cores, 1: Serial execution, n > 1: Use n workers. Defaults to 1. |
1
|
backend
|
str
|
Parallelisation backend. Options: 'multiprocessing', 'threading', 'joblib'. Defaults to 'multiprocessing'. |
'multiprocessing'
|
min_checks_for_parallel
|
int
|
Minimum number of checks required to trigger parallel execution. Defaults to 3. |
3
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid check names are provided or invalid format specified. |
Returns:
| Type | Description |
|---|---|
Union[str, Dict[str, Any]]
|
Union[str, Dict[str, Any]]: A comprehensive quality report in the specified format, or a structured dictionary if return_dict=True. |
Example
>>> # Text report
>>> report = df.lint.report()
>>> # HTML report
>>> df.lint.report(report_format='html', output='report.html')
>>> # JSON export
>>> df.lint.report(report_format='json', output='report.json')
>>> # CSV export
>>> df.lint.report(report_format='csv', output='issues.csv')
>>> # Get structured data
>>> data = df.lint.report(return_dict=True)
>>> # Parallel execution with all cores
>>> df.lint.report(n_jobs=-1)
>>> # Parallel execution with specific backend
>>> df.lint.report(n_jobs=4, backend='threading')
Source code in src/lintdata/accessor.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
unregister_check(name)
Remove a custom check function by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the custom check to remove. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the custom check is not registered. |
Source code in src/lintdata/accessor.py
options: show_root_heading: true show_source: false members: - report - register_check - unregister_check - list_custom_checks group_by_category: true show_signature_annotations: true separate_signature: true
Usage Examples
Basic Report
import pandas as pd
import lintdata
df = pd.read_csv("data.csv")
report = df.lint.report()
print(report)
Custom Configuration
# Run specific checks with custom thresholds
report = df.lint.report(
checks_to_run=["missing", "outliers", "duplicates"],
outlier_threshold=2.0,
skewness_threshold=0.5
)
Export Formats
# HTML report
df.lint.report(
report_format="html",
output="report.html"
)
# JSON export
json_data = df.lint.report(report_format="json")
# CSV export
df.lint.report(
report_format="csv",
output="issues.csv"
)
# Python dictionary
data = df.lint.report(return_dict=True)
Custom Checks
# Define custom check
def check_email_format(df):
warnings = []
for col in df.select_dtypes(include="object").columns:
if "email" in col.lower():
invalid = df[~df[col].str.contains("@", na=False)]
if len(invalid) > 0:
warnings.append(
f"[Email] Column '{col}': {len(invalid)} invalid email(s)"
)
return warnings
# Register and use
df.lint.register_check(check_email_format)
report = df.lint.report()
Parallel Execution
Validation Pipeline
def validate_dataset(df, config):
"""Validate DataFrame against quality standards."""
data = df.lint.report(
checks_to_run=config["checks"],
outlier_threshold=config["outlier_threshold"],
return_dict=True
)
if data["issue_count"] > config["max_issues"]:
raise ValueError(
f"Quality check failed: {data['issue_count']} issues found"
)
return data
# Use in pipeline
config = {
"checks": ["missing", "duplicates", "outliers"],
"outlier_threshold": 2.0,
"max_issues": 5
}
result = validate_dataset(df, config)
Parameter Reference
Check Selection
checks_to_run: List of check names or"all"- Available checks:
missing,duplicates,mixed_types,whitespace,constant,unique,outliers,missing_patterns,case,cardinality,skewness,duplicate_columns,type_consistency,negative,rare_categories,date_format,string_length,zero_inflation,future_dates,special_chars,date_anomalies,correlation,foreign_keys
Threshold Parameters
outlier_threshold(float): IQR multiplier for outliers (default: 1.5)skewness_threshold(float): Skewness detection threshold (default: 1.0)rare_category_threshold(float): Proportion for rare categories (default: 0.01)unique_column_threshold(float): Uniqueness threshold (default: 0.95)cardinality_high_threshold(int): High cardinality limit (default: 50)cardinality_low_threshold(int): Low cardinality limit (default: 2)string_length_threshold(float): String outlier threshold (default: 3.0)zero_inflation_threshold(float): Zero proportion threshold (default: 0.5)special_chars_threshold(float): Special char proportion (default: 0.1)threshold_years(float): Date range threshold in years (default: 50)correlation_threshold(float): Correlation threshold (default: 0.95)foreign_key_mappings(Dict[str, Union[pd.DataFrame, Tuple[pd.DataFrame, str]]]): Referential integrity mappings
Column-Specific Parameters
negative_value_columns(List[str]): Columns to check for negativesfuture_date_columns(List[str]): Columns to check for future datesfuture_date_reference(str): Reference date (YYYY-MM-DD)
Output Parameters
report_format(str): Output format -"text","html","json","csv"output(str): File path to save reportreturn_dict(bool): Return structured dictionary
Parallelisation Parameters
backend(str): Parallel backend -"joblib","threading", or"multiprocessing". Default:"multiprocessing".n_jobs(int): Number of parallel jobs. Default:-1(all cores)min_checks_for_parallel(int): Minimum checks to trigger automatic parallel execution (default: 3)
Design Patterns
Reusable Configuration
# Define standard config
STANDARD_CONFIG = {
"checks_to_run": ["missing", "duplicates", "outliers"],
"outlier_threshold": 2.0,
"report_format": "html"
}
# Apply to multiple DataFrames
for df in dataframes:
df.lint.report(**STANDARD_CONFIG, output=f"report_{df.name}.html")
Conditional Validation
# Validate only if conditions met
if df.shape[0] > 1000: # Large dataset
report = df.lint.report(
checks_to_run=["missing", "duplicates"],
cardinality_high_threshold=100
)