Skip to content

Return the cumulative max computed at every element.

Source code

Description

Return the cumulative max computed at every element.

Usage

<Expr>$cum_max(..., reverse = FALSE)

Arguments

These dots are for future extensions and must be empty.
reverse If TRUE, start from the last value.

Details

The Dtypes Int8, UInt8, Int16 and UInt16 are cast to Int64 before summing to prevent overflow issues.

Value

A polars expression

Examples

library("polars")

pl$DataFrame(a = c(1:4, 2L))$with_columns(
  cum_max = pl$col("a")$cum_max(),
  cum_max_reversed = pl$col("a")$cum_max(reverse = TRUE)
)
#> shape: (5, 3)
#> ┌─────┬─────────┬──────────────────┐
#> │ a   ┆ cum_max ┆ cum_max_reversed │
#> │ --- ┆ ---     ┆ ---              │
#> │ i32 ┆ i32     ┆ i32              │
#> ╞═════╪═════════╪══════════════════╡
#> │ 1   ┆ 1       ┆ 4                │
#> │ 2   ┆ 2       ┆ 4                │
#> │ 3   ┆ 3       ┆ 4                │
#> │ 4   ┆ 4       ┆ 4                │
#> │ 2   ┆ 4       ┆ 2                │
#> └─────┴─────────┴──────────────────┘