Skip to content
Latchkey

pandera pandas dtype mismatch in CI

pandera rejected a column because its pandas dtype does not match the schema. In CI this often stems from a different pandas version inferring types differently, or nulls promoting an int column to float or object.

What this error means

pandera raises a SchemaError about the series type, for example expecting int64 but getting object or float64, that reproduces in CI but not always locally.

pandera
pandera.errors.SchemaError: expected series 'quantity' to have type int64,
got float64

Common causes

Nulls promoted the column type

A single null in an integer column makes pandas store it as float64 (or object), which fails a strict int64 schema.

A different pandas version in CI

CI resolved a pandas version whose type inference differs from local, so the same data yields a different dtype.

How to fix it

Use a nullable dtype or coerce

  1. Declare a nullable integer dtype so nulls do not force a float.
  2. Or enable coerce=True to cast compatible types.
  3. Pin pandas so inference is consistent between local and CI.
schema.py
pa.Column(pd.Int64Dtype(), nullable=True)  # nullable integer, not float64

Pin the pandas version

Lock pandas so CI and local infer dtypes identically, removing environment-specific failures.

Terminal
python -m pip install "pandas==2.2.*"

How to prevent it

  • Use nullable dtypes for integer columns that can be null.
  • Pin pandas so type inference is reproducible.
  • Enable coercion for benign type differences.

Frequently asked questions

What causes "pandera dtype mismatch"?
A single null in an integer column makes pandas store it as float64 (or object), which fails a strict int64 schema.
How do I fix pandera dtype mismatch?
Use a nullable dtype or coerce

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card