pandera "SchemaError ... failed ... check" in CI
pandera validated a DataFrame against a schema and a column failed a check or dtype constraint, so schema.validate(df) raised SchemaError. This is a real data contract violation the schema is meant to enforce.
What this error means
A pandera-validated step raises "SchemaError: ... failed ... check" or "expected series to have type X, got Y", failing the pytest or script.
pandera.errors.SchemaError: Column 'age' failed element-wise validator
number 0: greater_than_or_equal_to(0)
failure cases: -3, -1 (2 of 1000 rows)Common causes
Data violates a column check
Values fall outside a range, pattern, or nullability the schema declares, so pandera lists the failure cases and raises.
A dtype mismatch
The column type does not match the schema (for example object instead of int64), often from an upstream read that inferred types differently.
How to fix it
Inspect failure cases and fix the data
- Read the
failure casespandera prints to see the offending values. - Fix the upstream transform, or coerce dtypes on read.
- Use
lazy=Trueto collect all failures at once when debugging.
try:
schema.validate(df, lazy=True)
except pa.errors.SchemaErrors as exc:
print(exc.failure_cases)
raise SystemExit(1)Coerce dtypes to match the schema
Enable coercion so compatible types are cast, rather than failing on a benign dtype difference.
schema = pa.DataFrameSchema(
{"age": pa.Column(int, pa.Check.ge(0))},
coerce=True,
)How to prevent it
- Validate with
lazy=Truein CI to surface every failure at once. - Enable
coerce=Truefor benign dtype differences. - Set explicit dtypes when reading data so pandas does not misinfer.