Skip to content

Collected

Collected

Collected(
    collection: Collection[Any, Unpack[tuple[Any, ...]]],
    parts: tuple[Any, ...],
)

Bases: Generic[D, Unpack[Columns]]

A collection's values, evaluated: what Collection.collect() and zk.collect_all give. It has the collection's dims, rows and column types (Collected[SomeDims, zk.FloatA["gross"]] in annotations, as for Collection) and holds every value as data:

  • a constant column as a (rows,) numpy array;
  • an array column as a (rows, length) numpy array;
  • a jagged column as a (counts, values) pair: counts a (rows, length) int array of how many values each entry holds, and values every value, row after row, then entry after entry.

It has no arithmetic: compute with the lazy Collection and collect the results.

dims property

dims: list[Dim]

The dims, in sort order, as for Collection.dims.

column_names property

column_names: list[str]

The value columns' names, in order.

types property

types: list[Any]

The value columns' types, in order: zeki.FloatA and so on.

row_count property

row_count: int

The number of rows, as len(collected).

dim_rows property

dim_rows: DimRows[D]

The rows' dims and dim cells, without values, as for Collection.dim_rows.

value_lengths property

value_lengths: list[int | None]

Each column's Values' length - an array's number of values, a jagged value's number of entries - in order, with None for a constant column.

to_numpy

to_numpy(name: str) -> Any

Column name's values: a (rows,) array for a constant column, a (rows, length) array for an array column, and a (counts, values) pair for a jagged one (see the class).

get_constant

get_constant(
    dim_row: tuple[str | int, ...], name: str
) -> Any

The value of the constant column name at dim_row - a tuple of the row's dim cells, () for a collection with no dims - as a Python value.

get_array

get_array(
    dim_row: tuple[str | int, ...], name: str
) -> NDArray[Any]

The array of the array column name at dim_row, as a (length,) numpy array.

get_jagged

get_jagged(
    dim_row: tuple[str | int, ...], name: str
) -> tuple[NDArray[int64], NDArray[Any]]

The jagged value of column name at dim_row, as a (counts, values) pair: how many values each entry holds, and the values, entry after entry.

to_list

to_list() -> list[tuple[dict[str, Any], dict[str, Any]]]

The values as plain Python: one (dim_row, value_row) pair per row, in row order. dim_row maps each dim's name to the row's dim cell - {} for a collection with no dims - and value_row maps each column's name to its value: the value itself for a constant column, a list for an array one, and a list of lists, one per entry, for a jagged one::

[
    (
        {"class_of_business": "motor", "underwriting_year": 2020},
        {"premium": 100.0, "gross": [1.0, 2.0], "large": [[5.0], []]},
    ),
]

to_polars

to_polars() -> DataFrame

The values as a Polars DataFrame, a row per row in row order: a column per dim - none for a collection with no dims - then a column per value column, of the kind's own dtype for a constant column, a pl.Array of it for an array one, and a pl.Array of pl.Lists, one per entry, for a jagged one. Raises ValueError if a dim and a value column share a name.

to_pandas

to_pandas() -> DataFrame | Series

A single-column collection's values as a pandas object, indexed by the dim rows: a DataFrame (rows x length) for an array column, or a Series for a constant one. A jagged column has no pandas form; read it with to_polars.

collect_all

collect_all(
    *collections: Collection[Any, Unpack[tuple[Any, ...]]],
) -> tuple[Collected[Any, Unpack[tuple[Any, ...]]], ...]

Evaluate collections together, with every copula registered so far applied, into a :class:Collected each, in order. The array columns of each kind and length across all of them are evaluated in one engine run, so work they share is done once - prefer it to collecting each in turn.