Checkers (dataspector.checkers)#
Format-agnostic data-integrity checkers.
Public facade re-exporting:
Source-level checks (
source_*) fromdataspector.checkers.sourceRecord-level checks (
record_*) fromdataspector.checkers.recordCheckOutcome,requires_all_data(), andREQUIRES_ALL_DATAfromdataspector.checkers.utils
Every check returns a CheckOutcome whose
passed attribute is:
True— check passed;False— check failed;None— indeterminate so far; keep streaming subsequent chunks.
Source-Level Checks#
Source-level and cross-source integrity check functions (alphabetical).
- dataspector.checkers.source.source_exists(source)[source]#
Check whether source exists.
- Parameters:
- source
Data source wrapper.
- Returns:
- CheckOutcome
passed=Trueif source exists, elseFalse.
- Parameters:
source (GenericData)
- Return type:
- dataspector.checkers.source.source_fuzzy_find(source, pattern)[source]#
Search source for files, sheets, or tables matching shell pattern.
- Parameters:
- source
Directory, workbook, or database source.
- pattern
Shell-style wildcard pattern (
*,?).
- Returns:
- CheckOutcome
Outcome listing matching entries in
notes.
- Parameters:
source (GenericData)
pattern (str)
- Return type:
- dataspector.checkers.source.source_has_N_fields(source, n_fields)[source]#
Check that source has exactly n_fields columns.
- Parameters:
- source
Data source wrapper.
- n_fields
Expected column count.
- Returns:
- CheckOutcome
Outcome with actual field count in
noteson mismatch.
- Parameters:
source (GenericData)
n_fields (int)
- Return type:
- dataspector.checkers.source.source_modified_on_date(source, date, tolerance='12h')[source]#
Check that source was last modified within tolerance of date.
- Parameters:
- source
Data source wrapper.
- date
Expected modification timestamp.
- tolerance
Pandas Timedelta string (e.g.
'1d','2.5h').
- Returns:
- CheckOutcome
Outcome with source modification timestamp in
notes.
- Parameters:
source (GenericData)
date (Any)
tolerance (str)
- Return type:
- dataspector.checkers.source.source_modified_recently(source, days_ago=1)[source]#
Check that source was modified within the last days_ago days.
- Parameters:
- source
Data source wrapper.
- days_ago
Maximum allowed age in days.
- Returns:
- CheckOutcome
Outcome with last modification timestamp in
noteswhen stale.
- Parameters:
source (GenericData)
days_ago (float)
- Return type:
- dataspector.checkers.source.source_source_identical(source, source2, shallow=False)[source]#
Check whether source and source2 are identical files on disk.
- Parameters:
- source
Primary file-backed data source.
- source2
Comparison file-backed data source.
- shallow
Compare only file metadata when
True; byte-by-byte whenFalse.
- Returns:
- CheckOutcome
Outcome indicating file identity.
- Parameters:
source (GenericData)
source2 (Any)
shallow (bool)
- Return type:
- dataspector.checkers.source.source_source_roughly_same_number_of_records(data, source2, tolerance=0.0, _last_chunk=True, _nrecords=0)[source]#
Check that the streamed source has roughly the same row count as source2.
Passes when
abs(n1 - n2) <= tolerance * n2(or both have zero records). Because this check is decorated withrequires_all_data(), it accumulates_nrecordsand returnspassed=Noneon intermediate chunks (_last_chunk=False) so the runner keeps streaming until the final chunk.- Parameters:
- data
Chunk of records from the primary source (any sized sequence/DataFrame).
- source2
Reference data source to compare against.
- tolerance
Relative difference threshold (default
0.0requires exact equality).- _last_chunk
Trueon the final chunk, triggering the comparison against source2.- _nrecords
Accumulated record count carried across chunks.
- Returns:
- CheckOutcome
passed=Nonewhile streaming;TrueorFalseon the final chunk.
- Parameters:
- Return type:
- dataspector.checkers.source.source_source_same_fields(source, source2)[source]#
Check that source and source2 expose the same set of fields.
- Parameters:
- source
Primary data source.
- source2
Comparison data source.
- Returns:
- CheckOutcome
Outcome detailing missing/extra columns in
noteson mismatch.
- Parameters:
source (GenericData)
source2 (Any)
- Return type:
- dataspector.checkers.source.source_source_size_roughly_same(source, source2, tolerance=0.2)[source]#
Check that source and source2 byte sizes are within tolerance.
- Parameters:
- source
Primary data source.
- source2
Comparison data source.
- tolerance
Maximum allowed relative difference
abs(size1 - size2) / size1.
- Returns:
- CheckOutcome
Outcome detailing relative size ratio in
noteson failure.
- Parameters:
source (GenericData)
source2 (Any)
tolerance (float)
- Return type:
- dataspector.checkers.source.source_storage_size_roughly(source, rough_size, tolerance=0.2)[source]#
Check that source byte size is within tolerance of rough_size.
- Parameters:
- source
Data source wrapper.
- rough_size
Expected size in bytes.
- tolerance
Maximum allowed relative difference.
- Returns:
- CheckOutcome
Outcome indicating whether the byte size is within tolerance.
- Parameters:
source (GenericData)
rough_size (int)
tolerance (float)
- Return type:
Record-Level Checks#
Record-level integrity check functions operating on DataFrame chunks (alphabetical).
- dataspector.checkers.record.record_all_data_not_null(data, _last_chunk=True)[source]#
Check that no cell anywhere in data is null/NaN.
- Parameters:
- data
Chunk of records.
- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Falseimmediately on any null;Nonewhile streaming;Trueat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_contains(data, field)[source]#
Check that data contains column field.
- Parameters:
- data
Chunk of records.
- field
Expected column name.
- Returns:
- CheckOutcome
Outcome listing available columns on failure.
- Parameters:
- Return type:
- dataspector.checkers.record.record_contains_at_least(data, fields)[source]#
Check that data contains every column listed in fields.
- Parameters:
- data
Chunk of records.
- fields
Required column names.
- Returns:
- CheckOutcome
Outcome listing missing columns on failure.
- Parameters:
- Return type:
- dataspector.checkers.record.record_count(data, nrows, _previous=0, _last_chunk=True)[source]#
Check that the dataset has exactly nrows rows across all streamed chunks.
- Parameters:
- data
Chunk of records.
- nrows
Expected total row count.
- _previous
Accumulated row count from prior chunks.
- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
passed=Nonewhile streaming;True/Falseon the final chunk.
- Parameters:
- Return type:
- dataspector.checkers.record.record_count_greater_than(data, nrows, _previous=0, _last_chunk=True)[source]#
Check that the dataset has strictly more than nrows rows.
- Parameters:
- data
Chunk of records.
- nrows
Exclusive minimum row count.
- _previous
Accumulated row count from prior chunks.
- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Trueas soon as nrows is exceeded;Nonewhile streaming;Falseat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_contains(data, field, value, _last_chunk=True)[source]#
Check that column field contains value at least once across chunks.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- value
Value to search for.
- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Trueas soon as value is seen;Nonewhile streaming;Falseif absent at end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_contains_at_least(data, field, values, _last_chunk=True, _found=None)[source]#
Check that column field contains every value in values across the dataset.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- values
Required values.
- _last_chunk
Trueon the final chunk.- _found
Accumulated unique values observed in prior chunks.
- Returns:
- CheckOutcome
Trueonce all values are observed;Nonewhile streaming;Falseat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_contains_only(data, field, values, _last_chunk=True, _found=None)[source]#
Check that column field contains no values outside values.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- values
Permitted values.
- _last_chunk
Trueon the final chunk.- _found
Accumulated unique values observed in prior chunks.
- Returns:
- CheckOutcome
Falseimmediately on unexpected values;Nonewhile streaming;Trueat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_date_between(data, field, constraint, include_bounds=False, _last_chunk=True)[source]#
Check that all date values in field lie within constraint.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- constraint
Lower and upper date bounds as a 2-sequence or bracketed string (e.g.
'[January 2015, 2018-01-01]'or(2015, 2018)).- include_bounds
Use inclusive bounds when
True, strict otherwise.- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Falseimmediately on out-of-range dates;Nonewhile streaming;Trueat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_is_numeric(data, field)[source]#
Check that column field has a numeric pandas dtype.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- Returns:
- CheckOutcome
Outcome detailing actual dtype on failure.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_is_unique(data, field, _last_chunk=True, _found=None)[source]#
Check that every value in field is unique across all chunks.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- _last_chunk
Trueon the final chunk.- _found
Accumulated values observed in prior chunks.
- Returns:
- CheckOutcome
Falseimmediately on duplicate values;Nonewhile streaming;Trueat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_not_null(data, field, _last_chunk=True)[source]#
Check that column field contains no null/NaN values.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Falseimmediately on any null;Nonewhile streaming;Trueat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_field_numeric_value_between(data, field, constraint, include_bounds=False, _last_chunk=True)[source]#
Check that all numeric values in field lie within constraint.
- Parameters:
- data
Chunk of records.
- field
Target column name.
- constraint
Lower and upper bounds as a 2-sequence or string (e.g.
'(0.1, 100)').- include_bounds
Use inclusive
<=/>=bounds whenTrue, strict otherwise.- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Falseimmediately on out-of-range values;Nonewhile streaming;Trueat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_if_field1_startswith_field2_contains_only(data, field1, value1, field2, value2, _last_chunk=True)[source]#
Check conditional dependency: if field1 starts with value1, field2 equals value2.
- Parameters:
- data
Chunk of records.
- field1
Condition column name.
- value1
Required prefix on field1.
- field2
Dependent column name.
- value2
Required value for field2 whenever field1 matches value1.
- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Falseimmediately on violations;Nonewhile streaming;Trueat end.
- Parameters:
- Return type:
- dataspector.checkers.record.record_validate_schema(data, schema, lazy=True, _last_chunk=True)[source]#
Validate each chunk of data against a Pandera
DataFrameSchema.Accepts a
pandera.pandas.DataFrameSchemaobject, a concise dict specification, a YAML/JSON schema file path, or a COBOL copybook path (auto-converted viato_pandera_schema()).- Parameters:
- data
Chunk of records to validate.
- schema
Declarative Pandera schema definition or path.
- lazy
Collect all schema violations per chunk before failing.
- _last_chunk
Trueon the final chunk.
- Returns:
- CheckOutcome
Outcome with concise violation summary in
noteson failure.
- Parameters:
- Return type:
Checker Utilities#
Shared types, decorators, and internal helpers for dataspector.checkers.
- class dataspector.checkers.utils.CheckOutcome(passed, notes=None, kwargs=<factory>)[source]#
Structured result returned by every check function in
dataspector.checkers.- Attributes:
- passed
Trueif the check passed,Falseif it failed, orNoneif more chunks must be streamed before deciding.- notes
Optional human-readable diagnostic details (e.g. failing row indices).
- kwargs
Keyword arguments (including updated accumulator state) forwarded to subsequent chunk invocations or recorded in reports.
- Parameters:
- dataspector.checkers.utils.requires_all_data(func)[source]#
Mark a check function as requiring the full streamed dataset before finalizing.
Decorated checks accept a
_last_chunk: bool = Trueparameter. While streaming chunks with_last_chunk=False, the check may returnCheckOutcome(passed=None, kwargs=...)to instructCheckeredHistoryto keep streaming and pass the updatedkwargsinto the next chunk. On the final flush (_last_chunk=True), the check must emit a definiteTrueorFalse.- Parameters:
- func
Check function to register in
REQUIRES_ALL_DATA.
- Returns:
- Callable
The original check function, unmodified.
- Parameters:
func (_F)
- Return type:
_F
- dataspector.checkers.utils.as_generic_data(source)[source]#
Coerce a path, tuple, or
GenericDataintoGenericData.- Parameters:
- source
File path, locator tuple, or existing
GenericDatawrapper.
- Returns:
- GenericData
Wrapped data source.
- Parameters:
source (Any)
- Return type:
- dataspector.checkers.utils.build_pandera_checks(spec)[source]#
Convert a simple dict of check constraints into
pandera.Checkobjects.
- dataspector.checkers.utils.check_series_between(series, lower, upper, include_bounds=False, last_chunk=True)[source]#
Evaluate range bounds on a numeric or datetime
pandas.Series.- Parameters:
- series
Values to test against the interval bounds.
- lower
Lower bound.
- upper
Upper bound.
- include_bounds
Treat lower and upper as inclusive when
True(exclusive whenFalse).- last_chunk
Whether this is the final chunk in a streaming check.
- Returns:
- tuple[bool | None, str | None]
Pair of
(passed, diagnostic_note);passedisNonewhile more chunks remain and no violation has occurred.
- Parameters:
- Return type:
- dataspector.checkers.utils.missing_field_note(field_name, data)[source]#
Format a consistent diagnostic note when a required column is absent.
- dataspector.checkers.utils.parse_date_bound(value)[source]#
Convert a string, year integer, or datetime-like bound to
pd.Timestamp.
- dataspector.checkers.utils.resolve_pandera_schema(schema)[source]#
Resolve a Pandera schema from an object, dict, YAML/JSON file, or COBOL copybook.
- Parameters:
- schema
Existing
pandera.pandas.DataFrameSchema, column-spec dictionary, JSON string, or path to a.json,.yaml/.yml, or COBOL copybook file.
- Returns:
- pandera.pandas.DataFrameSchema
Resolved Pandera DataFrame schema.
- Parameters:
- Return type:
DataFrameSchema
- dataspector.checkers.utils.source_byte_size(source)[source]#
Return file byte size for a file-backed or COBOL
GenericData.- Parameters:
- source
Data source wrapper backed by a local file or COBOL data file.
- Returns:
- int
Size of the underlying data file in bytes.
- Parameters:
source (GenericData)
- Return type:
- dataspector.checkers.utils.split_constraint(constraint)[source]#
Split a string like
'(0, 10)'/'[2020-01-01, 2021-01-01]'or 2-sequence.