Skip to main content
Version: Python

cum_max

cum_max calculates a cumulative maximum in an update_by table operation.

Syntax

cum_max(cols: list[str]) -> UpdateByOperation

Parameters

ParameterTypeDescription
colslist[str]

The column(s) to be operated on. These can include expressions to rename the output columns (e.g., NewCol = Col). If None, the cumulative maximum is calculated for all applicable columns in the table.

Returns

An UpdateByOperation to be used in an update_by table operation.

Examples

The following example performs an update_by on the source table using the cum_max operation. No grouping columns are given. As a result, the cumulative maximum is calculated for all rows.

from deephaven.updateby import cum_max
from deephaven import empty_table

source = empty_table(25).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0, 25)"]
)

result = source.update_by(ops=cum_max(cols=["MaxX = X"]), by=[])

The following example builds on the previous example by specifying Letter as the grouping column. Thus, the result table has cumulative maximum calculated per unique letter in that column.

from deephaven.updateby import cum_max
from deephaven import empty_table

source = empty_table(25).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0, 25)"]
)

result = source.update_by(ops=cum_max(cols=["MaxX = X"]), by=["Letter"])

The following example builds on the previous example by calculating the cumulative maximum for two columns using a single UpdateByOperation.

from deephaven.updateby import cum_max
from deephaven import empty_table

source = empty_table(25).update(
[
"Letter = (i % 2 == 0) ? `A` : `B`",
"X = randomInt(0, 25)",
"Y = randomInt(25, 50)",
]
)

result = source.update_by(ops=cum_max(cols=["MaxX = X", "MaxY = Y"]), by=["Letter"])

The following example builds on the previous example by specifying two key columns. Thus, each group is a unique combination of letter in the Letter column and boolean in the Truth column.

from deephaven.updateby import cum_max
from deephaven import empty_table

source = empty_table(25).update(
[
"Letter = (i % 2 == 0) ? `A` : `B`",
"Truth = randomBool()",
"X = randomInt(0, 25)",
"Y = randomInt(25, 50)",
]
)

result = source.update_by(
ops=cum_max(cols=["MaxX = X", "MaxY = Y"]), by=["Letter", "Truth"]
)