diff --git a/crates/polars-lazy/src/physical_plan/expressions/count.rs b/crates/polars-lazy/src/physical_plan/expressions/count.rs index 6dc754d59dc1..2479507bdf30 100644 --- a/crates/polars-lazy/src/physical_plan/expressions/count.rs +++ b/crates/polars-lazy/src/physical_plan/expressions/count.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use polars_core::prelude::*; -use polars_plan::dsl::consts::COUNT; +use polars_plan::dsl::consts::LEN; use crate::physical_plan::state::ExecutionState; use crate::prelude::*; @@ -12,7 +12,7 @@ pub struct CountExpr { impl CountExpr { pub(crate) fn new() -> Self { - Self { expr: Expr::Count } + Self { expr: Expr::Len } } } @@ -22,7 +22,7 @@ impl PhysicalExpr for CountExpr { } fn evaluate(&self, df: &DataFrame, _state: &ExecutionState) -> PolarsResult { - Ok(Series::new("count", [df.height() as IdxSize])) + Ok(Series::new("len", [df.height() as IdxSize])) } fn evaluate_on_groups<'a>( @@ -31,13 +31,13 @@ impl PhysicalExpr for CountExpr { groups: &'a GroupsProxy, _state: &ExecutionState, ) -> PolarsResult> { - let ca = groups.group_count().with_name(COUNT); + let ca = groups.group_count().with_name(LEN); let s = ca.into_series(); Ok(AggregationContext::new(s, Cow::Borrowed(groups), true)) } fn to_field(&self, _input_schema: &Schema) -> PolarsResult { - Ok(Field::new(COUNT, IDX_DTYPE)) + Ok(Field::new(LEN, IDX_DTYPE)) } fn as_partitioned_aggregator(&self) -> Option<&dyn PartitionedAggregation> { @@ -67,6 +67,6 @@ impl PartitionedAggregation for CountExpr { ) -> PolarsResult { // SAFETY: groups are in bounds. let agg = unsafe { partitioned.agg_sum(groups) }; - Ok(agg.with_name(COUNT)) + Ok(agg.with_name(LEN)) } } diff --git a/crates/polars-lazy/src/physical_plan/planner/expr.rs b/crates/polars-lazy/src/physical_plan/planner/expr.rs index 39d68c8901fb..55c0fc547f99 100644 --- a/crates/polars-lazy/src/physical_plan/planner/expr.rs +++ b/crates/polars-lazy/src/physical_plan/planner/expr.rs @@ -91,7 +91,7 @@ pub(crate) fn create_physical_expr( use AExpr::*; match expr_arena.get(expression).clone() { - Count => Ok(Arc::new(phys_expr::CountExpr::new())), + Len => Ok(Arc::new(phys_expr::CountExpr::new())), Window { mut function, partition_by, @@ -129,7 +129,7 @@ pub(crate) fn create_physical_expr( if apply_columns.is_empty() { if has_aexpr(function, expr_arena, |e| matches!(e, AExpr::Literal(_))) { apply_columns.push(Arc::from("literal")) - } else if has_aexpr(function, expr_arena, |e| matches!(e, AExpr::Count)) { + } else if has_aexpr(function, expr_arena, |e| matches!(e, AExpr::Len)) { apply_columns.push(Arc::from("count")) } else { let e = node_to_expr(function, expr_arena); diff --git a/crates/polars-lazy/src/physical_plan/planner/lp.rs b/crates/polars-lazy/src/physical_plan/planner/lp.rs index 1521018e89d5..ea47cf3308dc 100644 --- a/crates/polars-lazy/src/physical_plan/planner/lp.rs +++ b/crates/polars-lazy/src/physical_plan/planner/lp.rs @@ -38,7 +38,7 @@ fn partitionable_gb( let depth = (expr_arena).iter(*agg).count(); // These single expressions are partitionable - if matches!(aexpr, AExpr::Count) { + if matches!(aexpr, AExpr::Len) { continue; } // col() @@ -55,7 +55,7 @@ fn partitionable_gb( // count().alias() is allowed: count of 2 if depth <= 2 { match expr_arena.get(*input) { - AExpr::Count => {}, + AExpr::Len => {}, _ => { partitionable = false; break; @@ -103,7 +103,7 @@ fn partitionable_gb( Ternary {truthy, falsy, predicate,..} => { !has_aggregation(*truthy) && !has_aggregation(*falsy) && !has_aggregation(*predicate) } - Column(_) | Alias(_, _) | Count | Literal(_) | Cast {..} => { + Column(_) | Alias(_, _) | Len | Literal(_) | Cast {..} => { true } _ => { diff --git a/crates/polars-lazy/src/tests/aggregations.rs b/crates/polars-lazy/src/tests/aggregations.rs index 9f46823ae750..c54e584f2731 100644 --- a/crates/polars-lazy/src/tests/aggregations.rs +++ b/crates/polars-lazy/src/tests/aggregations.rs @@ -243,8 +243,8 @@ fn test_binary_agg_context_0() -> PolarsResult<()> { .lazy() .group_by_stable([col("groups")]) .agg([when(col("vals").first().neq(lit(1))) - .then(repeat(lit("a"), count())) - .otherwise(repeat(lit("b"), count())) + .then(repeat(lit("a"), len())) + .otherwise(repeat(lit("b"), len())) .alias("foo")]) .collect() .unwrap(); diff --git a/crates/polars-lazy/src/tests/queries.rs b/crates/polars-lazy/src/tests/queries.rs index 85f1b7ac86dc..4d997343e68b 100644 --- a/crates/polars-lazy/src/tests/queries.rs +++ b/crates/polars-lazy/src/tests/queries.rs @@ -1807,7 +1807,7 @@ fn test_partitioned_gb_count() -> PolarsResult<()> { .group_by([col("col")]) .agg([ // we make sure to alias with a different name - count().alias("counted"), + len().alias("counted"), col("col").count().alias("count2"), ]) .collect()?; diff --git a/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs b/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs index 9581d6ca3350..16826434a96d 100644 --- a/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs +++ b/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs @@ -23,14 +23,14 @@ use crate::executors::sinks::group_by::aggregates::{AggregateFunction, SumAgg}; use crate::expressions::PhysicalPipedExpr; use crate::operators::DataChunk; -struct Count {} +struct Len {} -impl PhysicalIoExpr for Count { +impl PhysicalIoExpr for Len { fn evaluate_io(&self, _df: &DataFrame) -> PolarsResult { unimplemented!() } } -impl PhysicalPipedExpr for Count { +impl PhysicalPipedExpr for Len { fn evaluate(&self, chunk: &DataChunk, _lazy_state: &dyn Any) -> PolarsResult { // the length must match the chunks as the operators expect that // so we fill a null series. @@ -42,7 +42,7 @@ impl PhysicalPipedExpr for Count { } fn expression(&self) -> Expr { - Expr::Count + Expr::Len } } @@ -57,7 +57,7 @@ pub fn can_convert_to_hash_agg( .map(|(_, ae)| { match ae { AExpr::Agg(_) - | AExpr::Count + | AExpr::Len | AExpr::Cast { .. } | AExpr::Literal(_) | AExpr::Column(_) @@ -70,7 +70,7 @@ pub fn can_convert_to_hash_agg( } ae }) - .filter(|ae| matches!(ae, AExpr::Agg(_) | AExpr::Count)) + .filter(|ae| matches!(ae, AExpr::Agg(_) | AExpr::Len)) .count() == 1 && can_run_partitioned @@ -80,7 +80,7 @@ pub fn can_convert_to_hash_agg( node = *input } match expr_arena.get(node) { - AExpr::Count => true, + AExpr::Len => true, ae @ AExpr::Agg(agg_fn) => { matches!( agg_fn, @@ -128,9 +128,9 @@ where { match expr_arena.get(node) { AExpr::Alias(input, _) => convert_to_hash_agg(*input, expr_arena, schema, to_physical), - AExpr::Count => ( + AExpr::Len => ( IDX_DTYPE, - Arc::new(Count {}), + Arc::new(Len {}), AggregateFunction::Count(CountAgg::new()), ), AExpr::Agg(agg) => match agg { diff --git a/crates/polars-plan/src/dsl/consts.rs b/crates/polars-plan/src/dsl/consts.rs index bc8314bc71ec..acc4b4649fc2 100644 --- a/crates/polars-plan/src/dsl/consts.rs +++ b/crates/polars-plan/src/dsl/consts.rs @@ -1,3 +1,3 @@ -pub const COUNT: &str = "count"; +pub const LEN: &str = "len"; pub const LITERAL_NAME: &str = "literal"; diff --git a/crates/polars-plan/src/dsl/expr.rs b/crates/polars-plan/src/dsl/expr.rs index c14e8d339e28..b91deca57e9d 100644 --- a/crates/polars-plan/src/dsl/expr.rs +++ b/crates/polars-plan/src/dsl/expr.rs @@ -135,8 +135,7 @@ pub enum Expr { Exclude(Box, Vec), /// Set root name as Alias KeepName(Box), - /// Special case that does not need columns - Count, + Len, /// Take the nth column in the `DataFrame` Nth(i64), // skipped fields must be last otherwise serde fails in pickle @@ -223,7 +222,7 @@ impl Hash for Expr { options.hash(state); }, // already hashed by discriminant - Expr::Wildcard | Expr::Count => {}, + Expr::Wildcard | Expr::Len => {}, #[allow(unreachable_code)] _ => { // the panic checks if we hit this diff --git a/crates/polars-plan/src/dsl/functions/index.rs b/crates/polars-plan/src/dsl/functions/index.rs index 6d0d2528b46f..20e7245d4021 100644 --- a/crates/polars-plan/src/dsl/functions/index.rs +++ b/crates/polars-plan/src/dsl/functions/index.rs @@ -8,7 +8,7 @@ use super::*; pub fn arg_sort_by>(by: E, descending: &[bool]) -> Expr { let e = &by.as_ref()[0]; let name = expr_output_name(e).unwrap(); - int_range(lit(0 as IdxSize), count().cast(IDX_DTYPE), 1, IDX_DTYPE) + int_range(lit(0 as IdxSize), len().cast(IDX_DTYPE), 1, IDX_DTYPE) .sort_by(by, descending) .alias(name.as_ref()) } diff --git a/crates/polars-plan/src/dsl/mod.rs b/crates/polars-plan/src/dsl/mod.rs index d6356a8a0aed..6aa5fe8a3964 100644 --- a/crates/polars-plan/src/dsl/mod.rs +++ b/crates/polars-plan/src/dsl/mod.rs @@ -1760,16 +1760,16 @@ where } } -/// Count expression. -pub fn count() -> Expr { - Expr::Count +/// Return the number of rows in the context. +pub fn len() -> Expr { + Expr::Len } /// Return the cumulative count of the context. #[cfg(feature = "range")] pub fn cum_count(reverse: bool) -> Expr { let start = lit(1 as IdxSize); - let end = count() + lit(1 as IdxSize); + let end = len() + lit(1 as IdxSize); let mut range = int_range(start, end, 1, IDX_DTYPE); if reverse { range = range.reverse() diff --git a/crates/polars-plan/src/logical_plan/aexpr/mod.rs b/crates/polars-plan/src/logical_plan/aexpr/mod.rs index 50b00067025e..704d3fc1d1c7 100644 --- a/crates/polars-plan/src/logical_plan/aexpr/mod.rs +++ b/crates/polars-plan/src/logical_plan/aexpr/mod.rs @@ -15,7 +15,7 @@ use crate::dsl::function_expr::FunctionExpr; #[cfg(feature = "cse")] use crate::logical_plan::visitor::AexprNode; use crate::logical_plan::Context; -use crate::prelude::consts::COUNT; +use crate::prelude::consts::LEN; use crate::prelude::*; #[derive(Clone, Debug, IntoStaticStr)] @@ -188,7 +188,7 @@ pub enum AExpr { offset: Node, length: Node, }, - Count, + Len, Nth(i64), } @@ -224,7 +224,7 @@ impl AExpr { | SortBy { .. } | Agg { .. } | Window { .. } - | Count + | Len | Slice { .. } | Gather { .. } | Nth(_) @@ -259,7 +259,7 @@ impl AExpr { use AExpr::*; match self { - Nth(_) | Column(_) | Literal(_) | Wildcard | Count => {}, + Nth(_) | Column(_) | Literal(_) | Wildcard | Len => {}, Alias(e, _) => container.push(*e), BinaryExpr { left, op: _, right } => { // reverse order so that left is popped first @@ -338,7 +338,7 @@ impl AExpr { pub(crate) fn replace_inputs(mut self, inputs: &[Node]) -> Self { use AExpr::*; let input = match &mut self { - Column(_) | Literal(_) | Wildcard | Count | Nth(_) => return self, + Column(_) | Literal(_) | Wildcard | Len | Nth(_) => return self, Alias(input, _) => input, Cast { expr, .. } => expr, Explode(input) => input, @@ -420,7 +420,7 @@ impl AExpr { pub(crate) fn is_leaf(&self) -> bool { matches!( self, - AExpr::Column(_) | AExpr::Literal(_) | AExpr::Count | AExpr::Nth(_) + AExpr::Column(_) | AExpr::Literal(_) | AExpr::Len | AExpr::Nth(_) ) } } diff --git a/crates/polars-plan/src/logical_plan/aexpr/schema.rs b/crates/polars-plan/src/logical_plan/aexpr/schema.rs index 282c1009ac69..6049f49695de 100644 --- a/crates/polars-plan/src/logical_plan/aexpr/schema.rs +++ b/crates/polars-plan/src/logical_plan/aexpr/schema.rs @@ -17,7 +17,7 @@ impl AExpr { use AExpr::*; use DataType::*; match self { - Count => Ok(Field::new(COUNT, IDX_DTYPE)), + Len => Ok(Field::new(LEN, IDX_DTYPE)), Window { function, .. } => { let e = arena.get(*function); e.to_field(schema, ctxt, arena) diff --git a/crates/polars-plan/src/logical_plan/conversion.rs b/crates/polars-plan/src/logical_plan/conversion.rs index fec74b7ecdb0..15b02e70522e 100644 --- a/crates/polars-plan/src/logical_plan/conversion.rs +++ b/crates/polars-plan/src/logical_plan/conversion.rs @@ -151,7 +151,7 @@ pub fn to_aexpr(expr: Expr, arena: &mut Arena) -> Node { length: to_aexpr(*length, arena), }, Expr::Wildcard => AExpr::Wildcard, - Expr::Count => AExpr::Count, + Expr::Len => AExpr::Len, Expr::Nth(i) => AExpr::Nth(i), Expr::SubPlan { .. } => panic!("no SQLSubquery expected at this point"), Expr::KeepName(_) => panic!("no `name.keep` expected at this point"), @@ -598,7 +598,7 @@ pub fn node_to_expr(node: Node, expr_arena: &Arena) -> Expr { offset: Box::new(node_to_expr(offset, expr_arena)), length: Box::new(node_to_expr(length, expr_arena)), }, - AExpr::Count => Expr::Count, + AExpr::Len => Expr::Len, AExpr::Nth(i) => Expr::Nth(i), AExpr::Wildcard => Expr::Wildcard, } diff --git a/crates/polars-plan/src/logical_plan/format.rs b/crates/polars-plan/src/logical_plan/format.rs index ff22c7345938..413818c46478 100644 --- a/crates/polars-plan/src/logical_plan/format.rs +++ b/crates/polars-plan/src/logical_plan/format.rs @@ -269,7 +269,7 @@ impl Debug for Expr { }, }, Nth(i) => write!(f, "nth({i})"), - Count => write!(f, "count()"), + Len => write!(f, "len()"), Explode(expr) => write!(f, "{expr:?}.explode()"), Alias(expr, name) => write!(f, "{expr:?}.alias(\"{name}\")"), Column(name) => write!(f, "col(\"{name}\")"), diff --git a/crates/polars-plan/src/logical_plan/iterator.rs b/crates/polars-plan/src/logical_plan/iterator.rs index 33296118ce31..e83952476d82 100644 --- a/crates/polars-plan/src/logical_plan/iterator.rs +++ b/crates/polars-plan/src/logical_plan/iterator.rs @@ -6,7 +6,7 @@ macro_rules! push_expr { ($current_expr:expr, $push:ident, $iter:ident) => {{ use Expr::*; match $current_expr { - Nth(_) | Column(_) | Literal(_) | Wildcard | Columns(_) | DtypeColumn(_) | Count => {}, + Nth(_) | Column(_) | Literal(_) | Wildcard | Columns(_) | DtypeColumn(_) | Len => {}, Alias(e, _) => $push(e), BinaryExpr { left, op: _, right } => { // reverse order so that left is popped first diff --git a/crates/polars-plan/src/logical_plan/optimizer/cse_expr.rs b/crates/polars-plan/src/logical_plan/optimizer/cse_expr.rs index 0b72b1a0073d..3e7891bc1c66 100644 --- a/crates/polars-plan/src/logical_plan/optimizer/cse_expr.rs +++ b/crates/polars-plan/src/logical_plan/optimizer/cse_expr.rs @@ -317,7 +317,7 @@ impl ExprIdentifierVisitor<'_> { // TODO! Add a typed null AExpr::Literal(LiteralValue::Null) => REFUSE_NO_MEMBER, AExpr::Column(_) | AExpr::Literal(_) | AExpr::Alias(_, _) => REFUSE_ALLOW_MEMBER, - AExpr::Count => { + AExpr::Len => { if self.is_group_by { REFUSE_NO_MEMBER } else { diff --git a/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/group_by.rs b/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/group_by.rs index 3ab423a6640d..cca7d1c3f1ac 100644 --- a/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/group_by.rs +++ b/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/group_by.rs @@ -52,7 +52,7 @@ pub(super) fn process_group_by( // Counts change due to groupby's // TODO! handle aliases, so that the predicate that is pushed down refers to the column before alias. let mut push_down = !has_aexpr(*predicate, expr_arena, |ae| { - matches!(ae, AExpr::Count | AExpr::Alias(_, _)) + matches!(ae, AExpr::Len | AExpr::Alias(_, _)) }); for name in aexpr_to_leaf_names_iter(*predicate, expr_arena) { diff --git a/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/mod.rs b/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/mod.rs index 4d9cbc2b46df..c9f08519ffb4 100644 --- a/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/mod.rs +++ b/crates/polars-plan/src/logical_plan/optimizer/predicate_pushdown/mod.rs @@ -530,7 +530,7 @@ impl<'a> PredicatePushDown<'a> { // a count is influenced by a Union/Vstack acc_predicates.retain(|_, predicate| { - if has_aexpr(*predicate, expr_arena, |ae| matches!(ae, AExpr::Count)) { + if has_aexpr(*predicate, expr_arena, |ae| matches!(ae, AExpr::Len)) { local_predicates.push(*predicate); false } else { diff --git a/crates/polars-plan/src/logical_plan/optimizer/projection_pushdown/projection.rs b/crates/polars-plan/src/logical_plan/optimizer/projection_pushdown/projection.rs index 8cf418011888..8e714a3a40ca 100644 --- a/crates/polars-plan/src/logical_plan/optimizer/projection_pushdown/projection.rs +++ b/crates/polars-plan/src/logical_plan/optimizer/projection_pushdown/projection.rs @@ -3,7 +3,7 @@ use super::*; fn is_count(node: Node, expr_arena: &Arena) -> bool { match expr_arena.get(node) { AExpr::Alias(node, _) => is_count(*node, expr_arena), - AExpr::Count => true, + AExpr::Len => true, _ => false, } } diff --git a/crates/polars-plan/src/logical_plan/tree_format.rs b/crates/polars-plan/src/logical_plan/tree_format.rs index d50d0432b756..a6dc2df4632f 100644 --- a/crates/polars-plan/src/logical_plan/tree_format.rs +++ b/crates/polars-plan/src/logical_plan/tree_format.rs @@ -53,7 +53,7 @@ impl UpperExp for AExpr { AExpr::Window { .. } => "window", AExpr::Wildcard => "*", AExpr::Slice { .. } => "slice", - AExpr::Count => "count", + AExpr::Len => "count", AExpr::Nth(v) => return write!(f, "nth({})", v), }; diff --git a/crates/polars-plan/src/logical_plan/visitor/expr.rs b/crates/polars-plan/src/logical_plan/visitor/expr.rs index 5dc3cc1cd6f7..36a7f3032546 100644 --- a/crates/polars-plan/src/logical_plan/visitor/expr.rs +++ b/crates/polars-plan/src/logical_plan/visitor/expr.rs @@ -153,7 +153,7 @@ impl AexprNode { (Gather { .. }, Gather { .. }) | (Filter { .. }, Filter { .. }) | (Ternary { .. }, Ternary { .. }) - | (Count, Count) + | (Len, Len) | (Slice { .. }, Slice { .. }) | (Explode(_), Explode(_)) => true, (SortBy { descending: l, .. }, SortBy { descending: r, .. }) => l == r, diff --git a/crates/polars-plan/src/utils.rs b/crates/polars-plan/src/utils.rs index 14ed716a0adc..523f3340d2ea 100644 --- a/crates/polars-plan/src/utils.rs +++ b/crates/polars-plan/src/utils.rs @@ -7,7 +7,7 @@ use smartstring::alias::String as SmartString; use crate::logical_plan::iterator::ArenaExprIter; use crate::logical_plan::Context; -use crate::prelude::consts::{COUNT, LITERAL_NAME}; +use crate::prelude::consts::{LEN, LITERAL_NAME}; use crate::prelude::*; /// Utility to write comma delimited strings @@ -178,7 +178,7 @@ pub fn expr_output_name(expr: &Expr) -> PolarsResult> { ComputeError: "this expression may produce multiple output names" ), - Expr::Count => return Ok(Arc::from(COUNT)), + Expr::Len => return Ok(Arc::from(LEN)), Expr::Literal(val) => { return match val { LiteralValue::Series(s) => Ok(Arc::from(s.name())), @@ -204,7 +204,7 @@ pub(crate) fn get_single_leaf(expr: &Expr) -> PolarsResult> { Expr::SortBy { expr, .. } => return get_single_leaf(expr), Expr::Window { function, .. } => return get_single_leaf(function), Expr::Column(name) => return Ok(name.clone()), - Expr::Count => return Ok(Arc::from(COUNT)), + Expr::Len => return Ok(Arc::from(LEN)), _ => {}, } } diff --git a/crates/polars-sql/src/functions.rs b/crates/polars-sql/src/functions.rs index 1bf567c6189d..478f78ad4ab8 100644 --- a/crates/polars-sql/src/functions.rs +++ b/crates/polars-sql/src/functions.rs @@ -1,6 +1,6 @@ use polars_core::prelude::{polars_bail, polars_err, PolarsResult}; use polars_lazy::dsl::Expr; -use polars_plan::dsl::{coalesce, concat_str, count, when}; +use polars_plan::dsl::{coalesce, concat_str, len, when}; use polars_plan::logical_plan::LiteralValue; use polars_plan::prelude::LiteralValue::Null; use polars_plan::prelude::{lit, StrptimeOptions}; @@ -1137,7 +1137,7 @@ impl SQLFunctionVisitor<'_> { let args = extract_args(self.func); match (self.func.distinct, args.as_slice()) { // count() - (false, []) => Ok(count()), + (false, []) => Ok(len()), // count(column_name) (false, [FunctionArgExpr::Expr(sql_expr)]) => { let expr = parse_sql_expr(sql_expr, self.ctx)?; @@ -1145,7 +1145,7 @@ impl SQLFunctionVisitor<'_> { Ok(expr.count()) }, // count(*) - (false, [FunctionArgExpr::Wildcard]) => Ok(count()), + (false, [FunctionArgExpr::Wildcard]) => Ok(len()), // count(distinct column_name) (true, [FunctionArgExpr::Expr(sql_expr)]) => { let expr = parse_sql_expr(sql_expr, self.ctx)?; diff --git a/crates/polars/tests/it/lazy/expressions/apply.rs b/crates/polars/tests/it/lazy/expressions/apply.rs index 749a9e21aa50..e4996920460a 100644 --- a/crates/polars/tests/it/lazy/expressions/apply.rs +++ b/crates/polars/tests/it/lazy/expressions/apply.rs @@ -9,7 +9,7 @@ fn test_int_range_agg() -> PolarsResult<()> { let out = df .lazy() - .with_columns([int_range(lit(0i32), count(), 1, DataType::Int64).over([col("x")])]) + .with_columns([int_range(lit(0i32), len(), 1, DataType::Int64).over([col("x")])]) .collect()?; assert_eq!( Vec::from_iter(out.column("literal")?.i64()?.into_no_null_iter()), diff --git a/crates/polars/tests/it/lazy/expressions/arity.rs b/crates/polars/tests/it/lazy/expressions/arity.rs index 095a7374b925..f51164b2862c 100644 --- a/crates/polars/tests/it/lazy/expressions/arity.rs +++ b/crates/polars/tests/it/lazy/expressions/arity.rs @@ -11,7 +11,7 @@ fn test_list_broadcast() { .unwrap() .lazy() .group_by([col("g")]) - .agg([col("a").unique_counts() * count()]) + .agg([col("a").unique_counts() * len()]) .collect() .unwrap(); } diff --git a/crates/polars/tests/it/lazy/expressions/slice.rs b/crates/polars/tests/it/lazy/expressions/slice.rs index 55e373352463..3cc1010d5bb5 100644 --- a/crates/polars/tests/it/lazy/expressions/slice.rs +++ b/crates/polars/tests/it/lazy/expressions/slice.rs @@ -15,7 +15,7 @@ fn test_slice_args() -> PolarsResult<()> { ]? .lazy() .group_by_stable([col("groups")]) - .agg([col("vals").slice(lit(0i64), count() * lit(0.2))]) + .agg([col("vals").slice(lit(0i64), len() * lit(0.2))]) .collect()?; let out = df.column("vals")?.explode()?; diff --git a/crates/polars/tests/it/lazy/expressions/window.rs b/crates/polars/tests/it/lazy/expressions/window.rs index 460a0a57b149..32a46fe01929 100644 --- a/crates/polars/tests/it/lazy/expressions/window.rs +++ b/crates/polars/tests/it/lazy/expressions/window.rs @@ -167,7 +167,7 @@ fn test_literal_window_fn() -> PolarsResult<()> { let out = df .lazy() - .select([repeat(1, count()) + .select([repeat(1, len()) .cum_sum(false) .over_with_options([col("chars")], WindowMapping::Join) .alias("foo")]) diff --git a/crates/polars/tests/it/lazy/predicate_queries.rs b/crates/polars/tests/it/lazy/predicate_queries.rs index 24f32546aee5..2af8a099e46e 100644 --- a/crates/polars/tests/it/lazy/predicate_queries.rs +++ b/crates/polars/tests/it/lazy/predicate_queries.rs @@ -221,7 +221,7 @@ fn test_count_blocked_at_union_3963() -> PolarsResult<()> { ..Default::default() }, )? - .filter(count().over([col("k")]).gt(lit(1))) + .filter(len().over([col("k")]).gt(lit(1))) .collect()?; assert!(out.equals(&expected)); diff --git a/docs/src/rust/user-guide/basics/expressions.rs b/docs/src/rust/user-guide/basics/expressions.rs index ac36b45f459a..ea6cae3c84af 100644 --- a/docs/src/rust/user-guide/basics/expressions.rs +++ b/docs/src/rust/user-guide/basics/expressions.rs @@ -102,12 +102,7 @@ fn main() -> Result<(), Box> { // --8<-- [end:dataframe2] // --8<-- [start:group_by] - let out = df2 - .clone() - .lazy() - .group_by(["y"]) - .agg([count()]) - .collect()?; + let out = df2.clone().lazy().group_by(["y"]).agg([len()]).collect()?; println!("{}", out); // --8<-- [end:group_by] diff --git a/docs/src/rust/user-guide/expressions/aggregation.rs b/docs/src/rust/user-guide/expressions/aggregation.rs index 2e061ac8e15a..532b89db9482 100644 --- a/docs/src/rust/user-guide/expressions/aggregation.rs +++ b/docs/src/rust/user-guide/expressions/aggregation.rs @@ -47,9 +47,9 @@ fn main() -> Result<(), Box> { .clone() .lazy() .group_by(["first_name"]) - .agg([count(), col("gender"), col("last_name").first()]) + .agg([len(), col("gender"), col("last_name").first()]) .sort( - "count", + "len", SortOptions { descending: true, nulls_last: true, diff --git a/docs/src/rust/user-guide/expressions/structs.rs b/docs/src/rust/user-guide/expressions/structs.rs index 7a1238154593..502f423fdf0d 100644 --- a/docs/src/rust/user-guide/expressions/structs.rs +++ b/docs/src/rust/user-guide/expressions/structs.rs @@ -1,5 +1,5 @@ // --8<-- [start:setup] -use polars::lazy::dsl::count; +use polars::lazy::dsl::len; use polars::prelude::*; // --8<-- [end:setup] fn main() -> Result<(), Box> { @@ -69,7 +69,7 @@ fn main() -> Result<(), Box> { // .filter(as_struct(&[col("Movie"), col("Theatre")]).is_duplicated()) // Error: .is_duplicated() not available if you try that // https://github.com/pola-rs/polars/issues/3803 - .filter(count().over([col("Movie"), col("Theatre")]).gt(lit(1))) + .filter(len().over([col("Movie"), col("Theatre")]).gt(lit(1))) .collect()?; println!("{}", &out); // --8<-- [end:struct_duplicates] @@ -91,7 +91,7 @@ fn main() -> Result<(), Box> { // .filter(as_struct(&[col("Movie"), col("Theatre")]).is_duplicated()) // Error: .is_duplicated() not available if you try that // https://github.com/pola-rs/polars/issues/3803 - .filter(count().over([col("Movie"), col("Theatre")]).gt(lit(1))) + .filter(len().over([col("Movie"), col("Theatre")]).gt(lit(1))) .collect()?; println!("{}", &out); // --8<-- [end:struct_ranking] diff --git a/docs/src/rust/user-guide/transformations/time-series/rolling.rs b/docs/src/rust/user-guide/transformations/time-series/rolling.rs index 5f5533d302ce..fc81f34412bb 100644 --- a/docs/src/rust/user-guide/transformations/time-series/rolling.rs +++ b/docs/src/rust/user-guide/transformations/time-series/rolling.rs @@ -140,7 +140,7 @@ fn main() -> Result<(), Box> { ..Default::default() }, ) - .agg([count()]) + .agg([len()]) .collect()?; println!("{}", &out); // --8<-- [end:group_by_dyn2] diff --git a/py-polars/src/functions/lazy.rs b/py-polars/src/functions/lazy.rs index 3f4a32e4a390..95e17d79601c 100644 --- a/py-polars/src/functions/lazy.rs +++ b/py-polars/src/functions/lazy.rs @@ -184,7 +184,7 @@ pub fn concat_str(s: Vec, separator: &str) -> PyExpr { #[pyfunction] pub fn len() -> PyExpr { - dsl::count().alias("len").into() + dsl::len().into() } #[pyfunction] diff --git a/py-polars/tests/unit/test_projections.py b/py-polars/tests/unit/test_projections.py index 51bd070e08b7..0a8c180806a1 100644 --- a/py-polars/tests/unit/test_projections.py +++ b/py-polars/tests/unit/test_projections.py @@ -290,7 +290,7 @@ def test_distinct_projection_pd_7578() -> None: }, schema_overrides={"len": pl.UInt32}, ) - assert_frame_equal(result, expected) + assert_frame_equal(result, expected, check_row_order=False) def test_join_suffix_collision_9562() -> None: