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
Parameter | Type | Description |
---|---|---|
cols | Union[str, list[str]] | The string names of columns to be operated on. These can include expressions to rename the output, e.g., |
delta_control | DeltaControl | Defines how special cases should behave. See |
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")])
- result
- source
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"])
- result
- source
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"]
)
- result
- source
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"])
- result
- source