Checkers (dataspector.checkers)#

Format-agnostic data-integrity checkers.

Public facade re-exporting:

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=True if source exists, else False.

Parameters:

source (GenericData)

Return type:

CheckOutcome

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:
Return type:

CheckOutcome

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 notes on mismatch.

Parameters:
Return type:

CheckOutcome

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:
Return type:

CheckOutcome

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 notes when stale.

Parameters:
Return type:

CheckOutcome

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 when False.

Returns:
CheckOutcome

Outcome indicating file identity.

Parameters:
Return type:

CheckOutcome

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 with requires_all_data(), it accumulates _nrecords and returns passed=None on 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.0 requires exact equality).

_last_chunk

True on the final chunk, triggering the comparison against source2.

_nrecords

Accumulated record count carried across chunks.

Returns:
CheckOutcome

passed=None while streaming; True or False on the final chunk.

Parameters:
Return type:

CheckOutcome

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 notes on mismatch.

Parameters:
Return type:

CheckOutcome

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 notes on failure.

Parameters:
Return type:

CheckOutcome

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:
Return type:

CheckOutcome

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

True on the final chunk.

Returns:
CheckOutcome

False immediately on any null; None while streaming; True at end.

Parameters:
Return type:

CheckOutcome

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:

CheckOutcome

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:

CheckOutcome

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

True on the final chunk.

Returns:
CheckOutcome

passed=None while streaming; True/False on the final chunk.

Parameters:
Return type:

CheckOutcome

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

True on the final chunk.

Returns:
CheckOutcome

True as soon as nrows is exceeded; None while streaming; False at end.

Parameters:
Return type:

CheckOutcome

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

True on the final chunk.

Returns:
CheckOutcome

True as soon as value is seen; None while streaming; False if absent at end.

Parameters:
Return type:

CheckOutcome

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

True on the final chunk.

_found

Accumulated unique values observed in prior chunks.

Returns:
CheckOutcome

True once all values are observed; None while streaming; False at end.

Parameters:
Return type:

CheckOutcome

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

True on the final chunk.

_found

Accumulated unique values observed in prior chunks.

Returns:
CheckOutcome

False immediately on unexpected values; None while streaming; True at end.

Parameters:
Return type:

CheckOutcome

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

True on the final chunk.

Returns:
CheckOutcome

False immediately on out-of-range dates; None while streaming; True at end.

Parameters:
Return type:

CheckOutcome

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:

CheckOutcome

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

True on the final chunk.

_found

Accumulated values observed in prior chunks.

Returns:
CheckOutcome

False immediately on duplicate values; None while streaming; True at end.

Parameters:
Return type:

CheckOutcome

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

True on the final chunk.

Returns:
CheckOutcome

False immediately on any null; None while streaming; True at end.

Parameters:
Return type:

CheckOutcome

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 when True, strict otherwise.

_last_chunk

True on the final chunk.

Returns:
CheckOutcome

False immediately on out-of-range values; None while streaming; True at end.

Parameters:
Return type:

CheckOutcome

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

True on the final chunk.

Returns:
CheckOutcome

False immediately on violations; None while streaming; True at end.

Parameters:
Return type:

CheckOutcome

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.DataFrameSchema object, a concise dict specification, a YAML/JSON schema file path, or a COBOL copybook path (auto-converted via to_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

True on the final chunk.

Returns:
CheckOutcome

Outcome with concise violation summary in notes on failure.

Parameters:
Return type:

CheckOutcome

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

True if the check passed, False if it failed, or None if 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:
passed: bool | None#
notes: str | None#
kwargs: dict[str, Any]#
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 = True parameter. While streaming chunks with _last_chunk=False, the check may return CheckOutcome(passed=None, kwargs=...) to instruct CheckeredHistory to keep streaming and pass the updated kwargs into the next chunk. On the final flush (_last_chunk=True), the check must emit a definite True or False.

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 GenericData into GenericData.

Parameters:
source

File path, locator tuple, or existing GenericData wrapper.

Returns:
GenericData

Wrapped data source.

Parameters:

source (Any)

Return type:

GenericData

dataspector.checkers.utils.build_pandera_checks(spec)[source]#

Convert a simple dict of check constraints into pandera.Check objects.

Parameters:
spec

Mapping of constraint names (e.g. gt, in_range, isin) to arguments, an existing list of pandera.Check, or None.

Returns:
list[pandera.Check]

Constructed Pandera check instances.

Parameters:

spec (dict[str, Any] | list[Check] | None)

Return type:

list[Check]

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 when False).

last_chunk

Whether this is the final chunk in a streaming check.

Returns:
tuple[bool | None, str | None]

Pair of (passed, diagnostic_note); passed is None while more chunks remain and no violation has occurred.

Parameters:
Return type:

tuple[bool | None, str | None]

dataspector.checkers.utils.missing_field_note(field_name, data)[source]#

Format a consistent diagnostic note when a required column is absent.

Parameters:
field_name

Name of the missing column.

data

DataFrame whose columns were inspected.

Returns:
str

Human-readable diagnostic message listing available columns.

Parameters:
Return type:

str

dataspector.checkers.utils.parse_date_bound(value)[source]#

Convert a string, year integer, or datetime-like bound to pd.Timestamp.

Parameters:
value

Date string, integer year, or datetime-like object.

Returns:
pandas.Timestamp

Parsed timestamp bound.

Parameters:

value (Any)

Return type:

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:

schema (DataFrameSchema | dict[str, Any] | str | Path)

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:

int

dataspector.checkers.utils.split_constraint(constraint)[source]#

Split a string like '(0, 10)' / '[2020-01-01, 2021-01-01]' or 2-sequence.

Parameters:
constraint

Two-element sequence or bracketed comma-separated string.

Returns:
tuple[Any, Any]

(lower, upper) raw bound values.

Parameters:

constraint (str | Sequence[Any])

Return type:

tuple[Any, Any]

dataspector.checkers.utils.truncate_lines(indices, limit=10)[source]#

Return up to limit row indices with an overflow marker if truncated.

Parameters:
indices

Sequence of failing row indices.

limit

Maximum number of indices to retain before appending "and more".

Returns:
list[Any]

List of row indices, optionally followed by "and more".

Parameters:
Return type:

list[Any]