Simple table constructors
new_table
Columns are created using the following methods:
bool_col
byte_col
char_col
datetime_col
double_col
float_col
int_col
jobj_col
long_col
pyobj_col
short_col
string_col
from deephaven import new_table
from deephaven.column import string_col, int_col
result = new_table(
[
int_col("Integers", [1, 2, 3]),
string_col("Strings", ["These", "are", "Strings"]),
]
)
Formula columns
from deephaven import new_table
from deephaven.column import int_col
var = 3
def f(a, b):
return a + b
source = new_table([int_col("A", [1, 2, 3, 4, 5]), int_col("B", [10, 20, 30, 40, 50])])
result = source.update(formulas=["X = A + 3 * sqrt(B) + var + (int)f(A, B)"])
- source
- result
Array columns
from deephaven.column import InputColumn
from deephaven import new_table
from deephaven import dtypes
import numpy as np
int_array = dtypes.array(dtypes.int32, np.array([1, 2, 3], dtype=np.int32))
int_array_col = InputColumn("IntArrayCol", dtypes.int32_array, input_data=[int_array])
source = new_table([int_array_col])
- source
String columns
from deephaven import new_table
from deephaven.column import string_col, int_col
scores = new_table(
[
string_col("Name", ["James", "Lauren", "Zoey"]),
int_col("Math", [95, 72, 100]),
int_col("Science", [100, 78, 98]),
int_col("Art", [90, 92, 96]),
]
)
total = scores.update(formulas=["Total = Math + Science + Art"])
average = scores.update(formulas=["Average = (Math + Science + Art) / 3 "])
- total
- scores
- average
empty_table
from deephaven import empty_table
result = empty_table(5)
# Empty tables are often followed with a formula
result1 = result.update(formulas=["X = 5"])
- result
- result1
time_table
from deephaven import time_table
result = time_table(period="PT2S")
ring_table
from deephaven import time_table, ring_table
source = time_table("PT00:00:01")
result = ring_table(parent=source, capacity=3)
input_table
from deephaven import empty_table, input_table
from deephaven import dtypes as dht
# from an existing table
source = empty_table(10).update(["X = i"])
result = input_table(init_table=source)
# from scratch
my_col_defs = {"Integers": dht.int32, "Doubles": dht.double, "Strings": dht.string}
result2 = input_table(col_defs=my_col_defs)
- source
- result
- result2