Skip to content

Commit

Permalink
allow count in window expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed May 18, 2022
1 parent 8df2ba4 commit 44ca891
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions polars/polars-lazy/src/physical_plan/planner/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ impl DefaultPlanner {
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)) {
apply_columns.push(Arc::from("count"))
} else {
let e = node_to_expr(function, expr_arena);
return Err(PolarsError::ComputeError(
Expand Down
13 changes: 13 additions & 0 deletions py-polars/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,16 @@ def test_cumulative_eval_window_functions() -> None:
"val": [20, 40, 30, 2, 4, 3],
"cumulative_eval_max": [20, 40, 40, 2, 4, 4],
}


def test_count_window() -> None:
assert (
pl.DataFrame(
{
"a": [1, 1, 2],
}
)
.with_column(pl.count().over("a"))["count"]
.to_list()
== [2, 2, 1]
)

0 comments on commit 44ca891

Please sign in to comment.