Skip to main content
Version: Python

iter_dict

iter_dict returns a generator that iterates over one row at a time from a table into a dictionary. The dictionary maps column names to scalar values of the corresponding column data types.

If locking is not explicitly specified, this method will automatically lock to ensure that all data from an iteration is from a consistent table snapshot.

Syntax

iter_dict(cols: Optional[Union[str, Sequence[str]]] = None, chunk_size: int = 2048) -> Generator[Dict[str, Any], None, None]

Parameters

ParameterTypeDescription
colsUnion[str, Sequence[str]]

The columns to read. If not given, all columns are read. The default is None, which reads all columns.

chunk_sizeint

The number of rows internally read at a time by Deephaven. The default is 2048.

Returns

A generator that yields a dictionary of column names and scalar column values.

Examples

The following example iterates over a table and prints each value in each row:

from deephaven import empty_table

source = empty_table(6).update(
["X = randomInt(0, 10)", "Y = randomDouble(100, 200)", "Z = randomBool()"]
)

for chunk in source.iter_dict():
x = chunk["X"]
y = chunk["Y"]
z = chunk["Z"]
print(f"X: {x}\tY: {y}\tZ: {z}")

The following example iterates over a table and prints only the X and Z columns:

from deephaven import empty_table

source = empty_table(6).update(
["X = randomInt(0, 10)", "Y = randomDouble(100, 200)", "Z = randomBool()"]
)

for chunk in source.iter_dict(cols=["X", "Z"]):
x = chunk["X"]
z = chunk["Z"]
print(f"X: {x}\tZ: {z}")