Path: blob/main/crates/polars-expr/src/dispatch/extension.rs
7884 views
use std::sync::Arc;12use polars_core::error::PolarsResult;3use polars_core::prelude::*;4use polars_plan::dsl::{ColumnsUdf, SpecialEq};5use polars_plan::plans::IRExtensionFunction;67pub fn function_expr_to_udf(func: IRExtensionFunction) -> SpecialEq<Arc<dyn ColumnsUdf>> {8use IRExtensionFunction::*;9match func {10To(dtype) => map!(ext_to, dtype.clone()),11Storage => map!(ext_storage),12}13}1415fn ext_to(s: &Column, dtype: DataType) -> PolarsResult<Column> {16let DataType::Extension(typ, storage) = &dtype else {17polars_bail!(ComputeError: "ext.to() requires an Extension dtype")18};1920Ok(s.apply_unary_elementwise(|s| {21assert!(*s.dtype() == **storage);22s.clone().into_extension(typ.clone())23}))24}2526fn ext_storage(s: &Column) -> PolarsResult<Column> {27Ok(s.apply_unary_elementwise(|s| s.to_storage().clone()))28}293031