Skip to main content
Version: Python

Operators

Operators can be used to construct formulas. These operators include:

  • + Addition - Adds values.
  • - Subtraction - Subtracts right value from left value.
  • * Multiplication - Multiplies the left and right values.
  • / Division - Divides left value by the right value.
  • % Modulus - Divides left value by the right value and returns the remainder.
  • _ Underscore - Accesses an array of all values within the column.
  • [] - Index - Indexes array elements.
  • . Dot - Accesses members of a package or a class.
  • (type) Casting - Casts from one type to another.
  • >, >=, <, and <= Comparison operators - Returns greater than, greater than or equal, less than, and less than or equal.

Example

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(formulas=[
"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)"
])

In this example, comparison operators are used to grab specific integers from a table.

from deephaven import new_table
from deephaven.column import int_col

source = new_table([
int_col("Value", [0, 1, 2, 3, 4, 5, 6])
])

greaterThan = source.where(filters=["Value > 3"])
greaterThanOrEqual = source.where(filters=["Value >= 3"])
lessThan = source.where(filters=["Value < 3"])
lessThanOrEqual = source.where(filters=["Value <= 3"])