Skip to main content
Version: Python


Formulas are used to filter tables or to assign data to columns. The following language features can be used to construct a formula:


Boolean formulas

If a formula returns a boolean value (true or false), it is known as a boolean filter and can be used with filter methods. For example:

table.where(filters=["X > 3", "Y % 4 == 1", "Z.startsWith(`Deephaven`)"])

Boolean formulas in filter methods are also known as conditional filters.

Assignment formulas

If a formula returns a value, it can be used with selection methods to create columns. For example:

table.update(formulas=["X = 3.14", "Y = sqrt(A) + 3"])


Boolean formulas

Formulas designed to return a boolean value are useful to narrow data sets to only desired values. In this example, operators are used with functions to limit values in result tables.

from deephaven import new_table

from deephaven.column import string_col, int_col

def f(a, b):
return a * b

source = new_table(
string_col("X", ["A", "B", "C", "D", "E", "F", "G"]),
int_col("Y", [1, 2, 3, 4, 5, 6, 7]),
int_col("Z", [2, 3, 1, 2, 3, 1, 2]),

result = source.where(filters=["(int)f(Y, Z) > 9"])

Assignment formulas

Formulas can also assign new values. In this example, operators are used with objects to create new columns of values.

from deephaven import empty_table

class MyObj:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c

def compute(self, value1):
return self.a + value1

obj = MyObj(1, 2, 3)

result = empty_table(10).update(
"A = i",
"B = A * A",
"C = A / 2",
"D = A % 3",
"E = (int)C",
"F = A_[i-2]",
"G = obj.a",
"H = obj.compute(A)",
"I = sqrt(A)",