{"record":{"id":"73c60a67a709a81f","repo":"pola-rs/polars","slug":"can-not-get-dtype-of-enum-anyvalue","errorCode":null,"errorMessage":"can not get dtype of Enum AnyValue","messagePattern":"can not get dtype of Enum AnyValue","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":271,"sourceCode":"            Binary(_) | BinaryOwned(_) => DataType::Binary,\n            #[cfg(feature = \"dtype-date\")]\n            Date(_) => DataType::Date,\n            #[cfg(feature = \"dtype-time\")]\n            Time(_) => DataType::Time,\n            #[cfg(feature = \"dtype-datetime\")]\n            Datetime(_, tu, tz) => DataType::Datetime(*tu, (*tz).cloned()),\n            #[cfg(feature = \"dtype-datetime\")]\n            DatetimeOwned(_, tu, tz) => {\n                DataType::Datetime(*tu, tz.as_ref().map(|v| v.as_ref().clone()))\n            },\n            #[cfg(feature = \"dtype-duration\")]\n            Duration(_, tu) => DataType::Duration(*tu),\n            #[cfg(feature = \"dtype-categorical\")]\n            Categorical(_, _) | CategoricalOwned(_, _) => {\n                unimplemented!(\"can not get dtype of Categorical AnyValue\")\n            },\n            #[cfg(feature = \"dtype-categorical\")]\n            Enum(_, _) | EnumOwned(_, _) => unimplemented!(\"can not get dtype of Enum AnyValue\"),\n            List(s) => DataType::List(Box::new(s.dtype().clone())),\n            #[cfg(feature = \"dtype-array\")]\n            Array(s, size) => DataType::Array(Box::new(s.dtype().clone()), *size),\n            #[cfg(feature = \"dtype-struct\")]\n            Struct(_, _, fields) => DataType::Struct(fields.to_vec()),\n            #[cfg(feature = \"dtype-struct\")]\n            StructOwned(payload) => DataType::Struct(payload.1.clone()),\n            #[cfg(feature = \"dtype-decimal\")]\n            Decimal(_, p, s) => DataType::Decimal(*p, *s),\n            #[cfg(feature = \"object\")]\n            Object(o) => DataType::Object(o.type_name()),\n            #[cfg(feature = \"object\")]\n            ObjectOwned(o) => DataType::Object(o.0.type_name()),\n        }\n    }\n\n    /// Extract a numerical value from the AnyValue\n    #[doc(hidden)]","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-core/src/datatypes/any_value.rs#L253-L289","documentation":"AnyValue::dtype() panics for Enum/EnumOwned scalars. As with categoricals, an enum scalar holds only the category index and a reference to the frozen categories, so a faithful DataType::Enum cannot be produced cheaply and the arm is unimplemented.","triggerScenarios":"Calling .dtype() on an AnyValue obtained from an Enum column (pl.Enum([...])): df[\"grade\"].get(0).dtype(), or library code that maps scalars back to dtypes (e.g. inferring a schema from Python-side values).","commonSituations":"Schema-from-scalars utilities, generic scalar introspection after switching a column to pl.Enum for memory or correctness reasons.","solutions":["Read the dtype from the Series or schema rather than from an individual value","Convert the scalar to String when only the value is needed","Handle the Enum(_, _) AnyValue variant explicitly in Rust code that must inspect it"],"exampleFix":"# before\nav = df[\"grade\"].get(0)  # grade is pl.Enum\nav.dtype()  # panics\n\n# after\ndf[\"grade\"].dtype  # Enum dtype from the column\nav.cast(pl.String)  # value-only use","handlingStrategy":"validation","validationCode":"if isinstance(df[\"grade\"].dtype, pl.Enum):\n    dtype = df[\"grade\"].dtype\nelse:\n    dtype = df[\"grade\"].get(0).dtype()","typeGuard":"def scalar_dtype_safe(series: pl.Series, idx: int = 0):\n    if isinstance(series.dtype, (pl.Categorical, pl.Enum)):\n        return series.dtype\n    return series.get(idx).dtype()","tryCatchPattern":null,"preventionTips":["Keep enum dtype information in the schema, not in extracted scalars","Treat pl.Enum columns specially in generic scalar-introspection code"],"tags":["rust","polars","panic","unimplemented","any-value","enum","dtype"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}