Skip to main content
Version: Python

How to create and use input tables

Input tables allow users to enter new data into tables in two ways: programmatically, and manually through the UI.

In the first case, data is added to a table with add, an input table-specific method similar to merge. In the second case, data is added to a table through the UI by clicking on cells and typing in the contents, similar to a spreadsheet program like MS Excel.

Input tables come in two flavors:

  • append-only
    • An append-only input table puts any entered data at the bottom.
  • keyed
    • A keyed input table supports modification/deletion of contents, and allows access to rows by key.

We'll show you how to create and use both types in this guide.

Create an input table

First, you need to import the input_table method from the deephaven module.

from deephaven import input_table

An input table can be constructed from a pre-existing table or a list of column definitions. In either case, one or more key columns can be specified, which turns the table from an append-only input table to a keyed input table.

From a pre-existing table

Here, we will create an input table from a table that already exists in memory. In this case, we'll create one with empty_table.

from deephaven import empty_table, input_table

source = empty_table(10).update(["X = i"])

result = input_table(init_table=source)

From scratch

Here, we will create an input table from a list of column definitions. Column definitions must be defined in a dictionary.

from deephaven import input_table
from deephaven import dtypes as dht

my_col_defs = {"Integers": dht.int32, "Doubles": dht.double, "Strings": dht.string}

result = input_table(col_defs=my_col_defs)

The resulting table is initially empty, and ready to receive data.

Create a keyed input table

In the previous two examples, no key column was specified when creating the input tables. If one or more key columns is specified, the table becomes a keyed table.

Let's first specify one key column.

from deephaven import input_table
from deephaven import dtypes as dht

my_col_defs = {"Integers": dht.int32, "Doubles": dht.double, "Strings": dht.string}

result = input_table(col_defs=my_col_defs, key_cols="Integers")

In the case of multiple key columns, specify them in a list.

result = input_table(col_defs=my_col_defs, key_cols=["Integers", "Doubles"])

When creating a keyed input table from a pre-existing table, the key column(s) must satisfy uniqueness criteria. Each row or combination of rows in the initial table must not have repeating values. Take, for instance, the following table:

from deephaven import empty_table, input_table

source = empty_table(10).update(
[
"Sym = (i % 2 == 0) ? `A` : `B`",
"Marker = (i % 3 == 2) ? `J` : `K`",
"X = i",
"Y = sin(0.1 * X)",
]
)

A keyed input table can be created from the X and Y columns, since they have no repeating values, and are thus unique:

input_source = input_table(init_table=source, key_cols=["X", "Y"])

A keyed input table cannot be created from the Sym or Marker columns, since they have repeating values and combinations, and are thus not unique:

input_source = input_table(init_table=source, key_cols=["Sym", "Marker"])

Add data to the table

Programmatically

The input table class's add method is used to add data to the table. This method works similarly to a merge, where tables are stacked vertically. New data is added to the end of the input table.

note

To programmatically add data to an input table, the table schemas (column definitions) must match. These column definitions comprise the names and data types of every column in the table.

from deephaven import empty_table, input_table
from deephaven import dtypes as dht

column_defs = {"Integers": dht.int32, "Doubles": dht.double, "Strings": dht.string}

my_table = empty_table(5).update(
["Integers = i", "Doubles = (double)i", "Strings = `a`"]
)

my_input_table = input_table(col_defs=column_defs)
my_input_table.add(my_table)

Manually

To manually add data to an input table, simply click on the cell in which you wish to enter data. Type the value into the cell, hit enter, and it will appear.

img

Note that with a keyed input table, you can edit existing rows; however, adding a new row will erase previous rows with the same key.

img

info

Added rows aren't final until you hit the Commit button. If you edit an existing row in a keyed input table, the result is immediate.

img

Here are some things to consider when manually entering data into an input table:

  • Manually entered data in a table will not be final until the Commit button at the bottom right of the console is clicked.
  • Data added manually to a table must be of the correct type for its column. For instance, attempting to add a string value to an int column will fail.
  • Entering data in between populated cells and hitting Enter will add the data to the bottom of the column.

Any string column in Deephaven can contain a clickable link — the string just has to be formatted correctly.

img

Let's create an input table that we can add links to manually:

from deephaven import dtypes as dht, input_table

my_col_defs = {
"Title": dht.string,
"Link": dht.string,
}

result = input_table(col_defs=my_col_defs)

img