pola-rs/polars · error
can not get dtype of Enum AnyValue
Error message
can not get dtype of Enum AnyValue
What it means
Like Categorical, AnyValue::Enum/EnumOwned stores only the physical index and AnyValue::dtype() has no access to the Enum's ordered categories, so reconstructing DataType::Enum is impossible and the code panics with unimplemented!.
Solutions
- Read the dtype from the Series (series.dtype()) rather than from the AnyValue.
- Cast the series to String/Utf8 before extracting per-value data if you need the category text.
- Match Enum variants explicitly in scalar code and consult the Enum's DataType (which you must hold alongside) for category info.
- Skip Enum columns in generic scalar inspection code, treating them like Categorical.
Example fix
// before let dtype = av.dtype(); // panics for Enum AnyValues // after let dtype = enum_series.dtype(); // DataType::Enum(categories, ordering)
Defensive patterns
Strategy: type-guard
Validate before calling
fn scalar_dtype(av: &AnyValue) -> Option<DataType> {
match av {
AnyValue::Enum(..) | AnyValue::EnumOwned(..) => None,
_ => Some(av.dtype()),
}
} Type guard
if matches!(av, AnyValue::Enum(..) | AnyValue::EnumOwned(..)) { /* use series dtype */ } Prevention
- Don't call dtype() on Enum AnyValues; use the owning Series' dtype
- Cast Enum columns to String to read category text per value
- Keep the DataType::Enum metadata alongside extracted scalars
When it happens
Trigger: Calling .dtype() on an AnyValue::Enum or AnyValue::EnumOwned, e.g. via get()/iter() on an Enum-typed series or via generic code paths that invoke dtype() on any extracted scalar.
Common situations: Working with DataType::Enum columns (fixed set of categories) and inspecting single values; generic scalar-processing helpers hitting Enum values at runtime.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- can not get dtype of Categorical AnyValue
- can't order enums from different FrozenCategories
- comparing enums with different FrozenCategories is not…
- invalid call to `get_strftime_format`; fmt=
- activate dtype
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/73c60a67a709a81f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-core/src/datatypes/any_value.rs:255
Binary(_) | BinaryOwned(_) => DataType::Binary,
#[cfg(feature = "dtype-date")]
Date(_) => DataType::Date,
#[cfg(feature = "dtype-time")]
Time(_) => DataType::Time,
#[cfg(feature = "dtype-datetime")]
Datetime(_, tu, tz) => DataType::Datetime(*tu, (*tz).cloned()),
#[cfg(feature = "dtype-datetime")]
DatetimeOwned(_, tu, tz) => {
DataType::Datetime(*tu, tz.as_ref().map(|v| v.as_ref().clone()))
},
#[cfg(feature = "dtype-duration")]
Duration(_, tu) => DataType::Duration(*tu),
#[cfg(feature = "dtype-categorical")]
Categorical(_, _) | CategoricalOwned(_, _) => {
unimplemented!("can not get dtype of Categorical AnyValue")
},
#[cfg(feature = "dtype-categorical")]
Enum(_, _) | EnumOwned(_, _) => unimplemented!("can not get dtype of Enum AnyValue"),
List(s) => DataType::List(Box::new(s.dtype().clone())),
#[cfg(feature = "dtype-map")]
Map(s) => {
let DataType::Struct(fields) = s.dtype() else {
unimplemented!("Map AnyValue payload must be a Struct")
};
DataType::Map(
Box::new(fields[0].dtype().clone()),
Box::new(fields[1].dtype().clone()),
)
},
#[cfg(feature = "dtype-array")]
Array(s, size) => DataType::Array(Box::new(s.dtype().clone()), *size),
#[cfg(feature = "dtype-struct")]
Struct(_, _, fields) => DataType::Struct(fields.to_vec()),
#[cfg(feature = "dtype-struct")]
StructOwned(payload) => DataType::Struct(payload.1.clone()),
#[cfg(feature = "dtype-decimal")]View on GitHub (pinned to fe841f959e)