Skip to main content
Version: Python

delta

delta calculates the difference between the current and previous cells. Null values in the current or previous cell, by default, produces null output. This behavior can be changed through the use of DeltaControl.

Syntax

delta(cols: list[str], delta_control: DeltaControl = None) -> UpdateByOperation

Parameters

ParameterTypeDescription
colsUnion[str, list[str]]

The string names of columns to be operated on. These can include expressions to rename the output, e.g., "new_col = col". When this parameter is left empty, update_by will perform the operation on all applicable columns.

delta_controlDeltaControl

Defines how special cases should behave. See DeltaControl.

Returns

An UpdateByOperation to be used in an update_by table operation.

Examples

One column, no groups

The following example performs an update_by on the source table using a delta operation, renaming the resulting column to DeltaX. No grouping columns are specified, so the delta is calculated over all rows.

from deephaven.updateby import delta
from deephaven import empty_table

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

result = source.update_by(ops=[delta(cols="DeltaX = X")])

One delta column, one grouping column

The following example builds on the previous by specifying Letter as the key column. Thus, the delta is calculated on a per-letter basis.

from deephaven.updateby import delta
from deephaven import empty_table

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

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

Multiple delta columns, multiple grouping columns

The following example builds on the previous by calculating the delta of multiple columns in the same UpdateByOperation. Also, the groups are defined by unique combinations of letter and boolean in the Letter and Truth columns, respectively.

from deephaven.updateby import delta
from deephaven import empty_table

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

result = source.update_by(
ops=delta(cols=["DeltaX = X", "DeltaY = Y"]), by=["Letter", "Truth"]
)

Multiple UpdateByOperations, multiple grouping columns

The following example builds on the previous by calculating the delta of multiple columns, each with its own UpdateByOperation. Also, the groups are defined by unique combinations of letter and boolean in the Letter and Truth columns, respectively.

from deephaven.updateby import delta
from deephaven import empty_table

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

delta_x = delta(cols=["DeltaX = X"])
delta_y = delta(cols=["DeltaY = Y"])

result = source.update_by(ops=[delta_x, delta_y], by=["Letter", "Truth"])