pola-rs/polars · error

dtype is unknown; consider supplying data-types for all oper

Error message

dtype is unknown; consider supplying data-types for all operations

What it means

When polars reconstructs a Series from raw Arrow chunks it matches on the DataType. DataType::Unknown means the type was never resolved (placeholder used before schema inference or when type information was dropped); it cannot back a Series, so the constructor panics with a hint to supply data-types for all operations.

Source

Thrown at crates/polars-core/src/series/from.rs:163

                if let Some(arr) = chunks[0].as_any().downcast_ref::<FixedSizeBinaryArray>() {
                    assert_eq!(chunks.len(), 1);
                    // SAFETY:
                    // this is highly unsafe. it will dereference a raw ptr on the heap
                    // make sure the ptr is allocated and from this pid
                    // (the pid is checked before dereference)
                    {
                        let pe = PolarsExtension::new(arr.clone());
                        let s = pe.get_series(&name);
                        pe.take_and_forget();
                        s
                    }
                } else {
                    unsafe { get_object_builder(name, 0).from_chunks(chunks) }
                }
            },
            Null => new_null(name, &chunks),
            Unknown(_) => {
                panic!("dtype is unknown; consider supplying data-types for all operations")
            },
            #[allow(unreachable_patterns)]
            _ => unreachable!(),
        }
    }

    /// # Safety
    /// The caller must ensure that the given `dtype` matches all the `ArrayRef` dtypes.
    pub unsafe fn _try_from_arrow_unchecked(
        name: PlSmallStr,
        chunks: Vec<ArrayRef>,
        dtype: &ArrowDataType,
    ) -> PolarsResult<Self> {
        Self::_try_from_arrow_unchecked_with_md(name, chunks, dtype, None)
    }

    /// Create a new Series without checking if the inner dtype of the chunks is correct
    ///

View on GitHub (pinned to 68506541d2)

Solutions

  1. Supply a full schema: pass schema= to scan_csv/scan_ipc or set infer_schema_length > 0
  2. Cast/resolve the column to a concrete dtype before converting to Series or executing
  3. Validate that no column in the plan has dtype Unknown before execution and fail with a descriptive error

Example fix

# before
lf = pl.scan_csv("f.csv", schema={"a": pl.Unknown, "b": pl.Int64})
lf.collect()  # panics

# after
lf = pl.scan_csv("f.csv", infer_schema_length=1000)
lf.collect()
Defensive patterns

Strategy: validation

Validate before calling

fn schema_fully_typed(schema: &Schema) -> bool {
    schema.iter_values().all(|dt| !matches!(dt, DataType::Unknown(_)))
}

Prevention

When it happens

Trigger: Series::from chunks whose schema carries unknown/placeholder types: lazy scans where the schema was not supplied (scan_csv/scan_ipc without schema or inference), custom FFI code passing Unknown dtypes, or plans executed before type resolution.

Common situations: scan_* with schema overrides that leave columns untyped; Arrow data crossing systems that discard type metadata; queries built dynamically where a projection references a column with no known dtype; bugs in code that constructs DataType::Unknown placeholders.

Related errors


AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-19). Data as JSON: /api/errors/b1caf47e06d0c480. Report an issue: GitHub.