pola-rs/polars · error

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

Error message

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

What it means

`Series::from_chunks_and_dtype_unchecked` matches on the provided DataType; `DataType::Unknown(_)` is a placeholder dtype (e.g. from lazily-typed or not-yet-resolved sources) and materializing chunks with an unknown dtype is invalid, so it panics telling the caller to supply concrete data types. It is a misuse of an unchecked constructor rather than a recoverable data error.

Solutions

  1. Resolve the dtype before construction — supply a concrete DataType (e.g. Int64, Utf8) to from_chunks_and_dtype_unchecked.
  2. Use a checked constructor like `Series::from_arrow` or `new_series` that infers or validates the dtype.
  3. If the dtype comes from a lazy source, call schema resolution (e.g. `collect_schema()`/`resolve`) before materializing chunks.

Example fix

// before
let s = Series::from_chunks_and_dtype_unchecked("a".into(), chunks, DataType::Unknown(None)); // panics

// after
let s = Series::from_chunks_and_dtype_unchecked("a".into(), chunks, DataType::Int64);
Defensive patterns

Strategy: validation

Validate before calling

if matches!(dtype, DataType::Unknown(_)) {
    panic!("resolve dtype before from_chunks_and_dtype_unchecked"); // or substitute a concrete dtype
}

Type guard

fn is_resolved(dt: &DataType) -> bool {
    !matches!(dt, DataType::Unknown(_))
}

Prevention

When it happens

Trigger: Calling `Series::from_chunks_and_dtype_unchecked(name, chunks, DataType::Unknown)` (or via code paths that propagate an unresolved dtype from scan/arrow metadata); building Series from a lazy plan whose dtype was never resolved.

Common situations: Plugin/connector code copying dtypes from untyped Arrow metadata; caching dtype values before schema resolution and reusing them in unchecked constructors; tests that stub dtypes with Unknown.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/b1caf47e06d0c480. Report an issue: GitHub.

Appendix: source

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

                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 fe841f959e)