pola-rs/polars · error

dtype not supported

Error message

dtype {:?} not supported

What it means

This panic comes from a Polars internal match macro that dispatches operations per DataType. It fires when the operation is invoked on a dtype that has no mapping in the macro arms — specifically BinaryOffset or Unknown. It means the engine reached a code path with a dtype representation it cannot handle for this operation.

Solutions

  1. Cast the column to a supported dtype first, e.g. df.with_columns(pl.col('c').cast(pl.Binary)) — BinaryOffset maps to plain Binary at the Python surface.
  2. Check polars version alignment: ensure the same polars version produced and consumes any serialized plans/IPC data so Unknown dtypes don't appear.
  3. If BinaryOffset is surfaced unexpectedly, upgrade polars; internal offset variants are usually transient representations.
  4. Report the specific operation + dtype to the Polars maintainers if you hit it with a normal Binary column — it indicates a missed dispatch arm.

Example fix

// before
df.select(pl.col("payload").str.len_bytes())
// after
df.select(pl.col("payload").cast(pl.Binary).str.len_bytes())
Defensive patterns

Strategy: validation

Validate before calling

import polars as pl
assert df.schema["payload"] != pl.Unknown, "dtype unresolved; cannot dispatch"
assert df.schema["payload"].is_not_unknown()

Type guard

def has_supported_dtype(col: pl.Expr, df: pl.DataFrame) -> bool:
    return not isinstance(df.schema.get(col.meta.output_name()), (pl.Unknown,))

Try / catch

try:
    out = df.select(pl.col("payload").str.len_bytes())
except pl.exceptions.PolarsPanicError as e:
    out = df.with_columns(pl.col("payload").cast(pl.Binary)).select(pl.col("payload").str.len_bytes())

Prevention

When it happens

Trigger: Calling any expression/dtype-dispatched operation (via the match_dtype_to_physical/macro machinery in crates/polars-python/src/utils.rs) on a Series or expression whose DataType is DataType::BinaryOffset or DataType::Unknown(_).

Common situations: Working with large Binary/BinaryOffset columns produced internally by Polars (e.g. from certain IO or string caches), or handling a dtype that failed to resolve (Unknown) after deserialization of a lazy plan across version mismatch, then applying a per-dtype dispatched operation.

Related errors


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

Appendix: source

Thrown at crates/polars-python/src/utils.rs:68

                CategoricalPhysical::U8 => $self.cat8().unwrap().$method($($args),*),
                CategoricalPhysical::U16 => $self.cat16().unwrap().$method($($args),*),
                CategoricalPhysical::U32 => $self.cat32().unwrap().$method($($args),*),
            },

            #[cfg(feature = "object")]
            DataType::Object(_) => {
                $self
                .as_any()
                .downcast_ref::<ObjectChunked<ObjectValue>>()
                .unwrap()
                .$method($($args),*)
            },
            DataType::Map(_, _) => $self.map().unwrap().$method($($args),*),
            DataType::Extension(_, _) => $self.ext().unwrap().$method($($args),*),

            DataType::Null => $self.null().unwrap().$method($($args),*),

            dt @ (DataType::BinaryOffset | DataType::Unknown(_)) => panic!("dtype {:?} not supported", dt)
        }
    }
}

/// Boilerplate for `|e| PyPolarsErr::from(e).into()`
#[allow(unused)]
pub(crate) fn to_py_err<E: Into<PyPolarsErr>>(e: E) -> PyErr {
    e.into().into()
}

pub trait EnterPolarsExt {
    /// Whenever you have a block of code in the public Python API that
    /// (potentially) takes a long time, wrap it in enter_polars. This will
    /// ensure we release the GIL and catch KeyboardInterrupts.
    ///
    /// This not only can increase performance and usability, it can avoid
    /// deadlocks on the GIL for Python UDFs.
    fn enter_polars<T, E, F>(self, f: F) -> PyResult<T>

View on GitHub (pinned to fe841f959e)