pola-rs/polars · critical

this type isn't exposed to python

Error message

this type isn't exposed to python

What it means

When converting a Rust polars DataType into a Python dtype object, DataType::BinaryOffset has no Python-visible counterpart, so the conversion panics with 'this type isn't exposed to python'. This is an internal invariant: BinaryOffset should never reach the Python boundary.

Solutions

  1. Normalize BinaryOffset to pl.Binary before crossing the Python boundary (cast or map the dtype).
  2. Fix the Rust-side code so internal dtypes never reach IntoPyObject conversions.
  3. Report to polars if a public API surfaces BinaryOffset in a schema.

Example fix

// before
let py_dtype = dtype.into_pyobject(py)?; // panics for BinaryOffset
// after
let dtype = match dtype { DataType::BinaryOffset => DataType::Binary, d => d };
let py_dtype = dtype.into_pyobject(py)?;
Defensive patterns

Strategy: type-guard

Validate before calling

# Rust: check before converting
if matches!(dtype, DataType::BinaryOffset) {
    return Err(PyValueError::new_err("BinaryOffset is not Python-exposed; use Binary"));
}

Type guard

fn is_python_exposed(dtype: &DataType) -> bool {
    !matches!(dtype, DataType::BinaryOffset)
}

Try / catch

# Python side: catch the panic-derived error at the boundary
try:
    py_dtype = rust_dtype.to_python()
except BaseException as e:
    raise TypeError(f"dtype not convertible to Python: {e}") from e

Prevention

When it happens

Trigger: Rust code producing a schema/dtype containing BinaryOffset (the chunked-offset binary representation used internally) and then converting it via into_pyobject / IntoPyObject for DataType.

Common situations: Plugin or FFI code leaking internal representations into Python-facing APIs; reading schemas from low-level paths that preserve BinaryOffset; polars version drift where internal dtypes reach conversion code.

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/bb6a94f25e53010a. Report an issue: GitHub.

Appendix: source

Thrown at pyo3-polars/pyo3-polars/src/types.rs:484

                    })
                    .collect::<PyResult<Vec<_>>>()?;
                let fields = PyList::new(py, iter)?;
                let struct_class = pl.getattr(intern!(py, "Struct")).unwrap();
                struct_class.call1((fields,))
            },
            DataType::Null => {
                let class = pl.getattr(intern!(py, "Null")).unwrap();
                class.call0()
            },
            DataType::Unknown(UnknownKind::Int(v)) => {
                PyDataType(materialize_dyn_int(*v).dtype()).into_pyobject(py)
            },
            DataType::Unknown(_) => {
                let class = pl.getattr(intern!(py, "Unknown")).unwrap();
                class.call0()
            },
            DataType::BinaryOffset => {
                panic!("this type isn't exposed to python")
            },
            #[allow(unreachable_patterns)]
            _ => panic!("activate dtype"),
        }
    }
}

impl<'py> IntoPyObject<'py> for PySchema {
    type Target = PyDict;
    type Output = Bound<'py, Self::Target>;
    type Error = PyErr;

    fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
        let dict = PyDict::new(py);
        for (k, v) in self.0.iter() {
            dict.set_item(k.as_str(), PyDataType(v.clone()).into_pyobject(py)?)?;
        }
        Ok(dict)

View on GitHub (pinned to fe841f959e)