import pointblank as pb
import polars as pl
readings_contract = pb.Contract(
name="sensor_readings",
steps=[
pb.Step("col_vals_not_null", columns="sensor_id"),
pb.Step("col_vals_between", columns="temp_c", left=-40, right=60),
],
on_violation="raise",
)
ingest = pb.Pipeline(source=readings_contract, label="Sensor ingest")validate_source()
Check incoming data against the source contract.
Usage
validate_source(data)This method validates one table against the pipeline’s source contract and returns the interrogated Validate object. Use it when you want an ingestion check without running a transformation through the pipeline: for example, when data lands in one task of an orchestrated workflow and is transformed in another, or when the transformation is written in SQL or another tool. Pair it with validate_target() to check the other boundary.
The validation is built the same way as in run(), with the pipeline’s label, thresholds, and actions. If the data fails, the source contract’s on_violation= setting is applied. With on_violation="raise", this makes the method a simple gate: the code after the call only runs when the data meets the contract.
Parameters
data: IntoDataFrame- The incoming table. Any table type that Validate accepts can be used (e.g., a Polars or Pandas DataFrame, or an Ibis table).
Returns
Validate- An interrogated Validate object with the results of every source contract check.
Raises
ValueError-
If the pipeline has no source contract.
ContractViolationError-
If the data fails the source contract and the contract has
on_violation="raise". It’s a subclass ofRuntimeError, and itsvalidationattribute holds the failing validation.
Examples
Let’s make a pipeline that guards the ingestion of sensor readings. The source contract uses on_violation="raise", so readings that don’t meet it are rejected with an error.
A batch of good readings passes, and we get the validation back:
readings = pl.DataFrame({"sensor_id": ["s1", "s2", "s3"], "temp_c": [21.5, 19.0, 22.1]})
ingest.validate_source(readings)| Pointblank Validation | |||||||||||||
Sensor ingest [source] Polarssensor_readings |
|||||||||||||
| STEP | COLUMNS | VALUES | TBL | EVAL | UNITS | PASS | FAIL | W | E | C | EXT | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| #4CA64C | 1 |
col_vals_not_null()
|
✓ | 3 | 3 1.00 |
0 0.00 |
— | — | — | — | |||
| #4CA64C | 2 |
col_vals_between()
|
✓ | 3 | 3 1.00 |
0 0.00 |
— | — | — | — | |||
A batch with an impossible temperature raises a ContractViolationError (a kind of RuntimeError) naming the contract, so a job that loads the data can stop before anything is written.
bad_readings = pl.DataFrame({"sensor_id": ["s1", "s2"], "temp_c": [21.5, 85.0]})
try:
ingest.validate_source(bad_readings)
except RuntimeError as e:
print(f"Rejected: {e}")Rejected: Contract 'sensor_readings' (source) violated: validation has failing steps.
The message names the contract and its direction. If the contract used on_violation="warn" or "log" instead, the call would return the failing validation rather than raising, leaving it to the caller to decide what to do.