Path: blob/main/crates/polars-expr/src/expressions/count.rs
8422 views
use std::borrow::Cow;12use polars_core::prelude::*;3use polars_plan::constants::LEN;45use super::*;6use crate::expressions::{AggregationContext, PhysicalExpr};78pub struct CountExpr {9expr: Expr,10}1112impl CountExpr {13pub(crate) fn new() -> Self {14Self { expr: Expr::Len }15}16}1718impl PhysicalExpr for CountExpr {19fn as_expression(&self) -> Option<&Expr> {20Some(&self.expr)21}2223fn evaluate(&self, df: &DataFrame, _state: &ExecutionState) -> PolarsResult<Column> {24Ok(Column::new_scalar(25PlSmallStr::from_static(LEN),26Scalar::from(df.height() as IdxSize),271,28))29}3031fn evaluate_on_groups<'a>(32&self,33_df: &DataFrame,34groups: &'a GroupPositions,35_state: &ExecutionState,36) -> PolarsResult<AggregationContext<'a>> {37let ca = groups.group_count().with_name(PlSmallStr::from_static(LEN));38let c = ca.into_column();39Ok(AggregationContext::new(c, Cow::Borrowed(groups), true))40}4142fn to_field(&self, _input_schema: &Schema) -> PolarsResult<Field> {43Ok(Field::new(PlSmallStr::from_static(LEN), IDX_DTYPE))44}4546fn is_scalar(&self) -> bool {47true48}49}505152