Path: blob/main/crates/polars-expr/src/expressions/element.rs
7884 views
use polars_core::prelude::*;12use super::*;3use crate::expressions::{AggregationContext, PhysicalExpr};45#[derive(Debug)]6pub struct ElementExpr {7output_field: Field,8}910impl ElementExpr {11pub fn new(output_field: Field) -> Self {12Self { output_field }13}14}1516impl PhysicalExpr for ElementExpr {17fn as_expression(&self) -> Option<&Expr> {18Some(&Expr::Element)19}2021fn evaluate(&self, _df: &DataFrame, state: &ExecutionState) -> PolarsResult<Column> {22let (flattened, _validity) = state.element.as_ref().clone().ok_or_else(23|| polars_err!(InvalidOperation: "`element` is not allowed in this context"),24)?;25Ok(flattened)26}2728fn evaluate_on_groups<'a>(29&self,30df: &DataFrame,31groups: &'a GroupPositions,32state: &ExecutionState,33) -> PolarsResult<AggregationContext<'a>> {34let c = self.evaluate(df, state)?;35Ok(AggregationContext::new(c, Cow::Borrowed(groups), false))36}3738fn to_field(&self, _input_schema: &Schema) -> PolarsResult<Field> {39Ok(self.output_field.clone())40}4142fn is_scalar(&self) -> bool {43false44}45}464748