pola-rs/polars · critical
activate dtype
Error message
activate dtype
What it means
The catch-all arm of DataType's IntoPyObject conversion panics with 'activate dtype' when it encounters a DataType variant with no Python mapping. It signals an unhandled/exhaustiveness gap in the Rust-to-Python dtype conversion rather than a user error.
Solutions
- Update pyo3-polars/src/types.rs to map the missing DataType variant to its Python class.
- Align polars-core and pyo3-polars versions so all variants are covered.
- Work around by mapping the dtype to a supported equivalent before conversion.
Example fix
// before
DataType::SomeNewVariant => panic!("activate dtype"),
// after
DataType::SomeNewVariant => {
let class = pl.getattr(intern!(py, "SomeNewVariant"))?.cast()?;
class.call0()
}, Defensive patterns
Strategy: try-catch
Validate before calling
# Rust: guard before conversion
if !is_known_dtype_variant(&dtype) {
return Err(PyNotImplementedError::new_err(format!("no Python mapping for {dtype:?}")));
} Type guard
fn has_python_mapping(dtype: &DataType) -> bool {
!matches!(dtype, DataType::Unknown(_) | DataType::BinaryOffset)
} Try / catch
try:
schema = rust_schema.to_python()
except BaseException as e:
log.error("dtype conversion failed; aligning polars versions may fix it: %s", e)
raise Prevention
- Keep pyo3-polars and polars-core versions in lockstep.
- Add match arms for every DataType variant and avoid unreachable catch-alls hiding gaps.
- Add CI round-trip tests converting all DataType variants to Python.
When it happens
Trigger: Converting a schema or expression output dtype whose variant (e.g. a new or Unknown-shaped dtype added in polars core) is not covered by the explicit match arms in pyo3-polars/types.rs.
Common situations: Using a newer polars core with an older pyo3-polars so new DataType variants appear; plugin code returning dtypes that were never mapped for Python conversion.
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
- this type isn't exposed to python
- date not implemented for
- into_datetime not implemented for
- into_decimal( , ) not implemented for
- invalid from_physical
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/d54a0d7a5bc978ba.
Report an issue: GitHub.
Appendix: source
Thrown at pyo3-polars/pyo3-polars/src/types.rs:487
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)