Functions¶
Combining¶
concat ¶
concat(
items: Sequence[Collection[D, *tuple[Any, ...]]],
how: Literal["horizontal"] = ...,
) -> Collection[D, *tuple[Any, ...]]
The collections in items combined into one, with the first's dims
and column order. how="horizontal" (the default, unlike Polars) puts
their value columns side by side - the first's, then the second's and so
on - over the first's rows: every collection must have the same dims (in
any order) and dim rows, and no column name may repeat.
how="vertical" stacks their rows: every collection must have the same
dims (in any order) and the same value columns, each of the same type,
and no dim row may repeat. Raises ValueError otherwise.
Elementwise¶
min ¶
min(
a: Collection[Any, Any] | Scalar,
b: Collection[Any, Any] | Scalar,
) -> Collection[Any, Any]
Elementwise minimum of two operands of one kind.
max ¶
max(
a: Collection[Any, Any] | Scalar,
b: Collection[Any, Any] | Scalar,
) -> Collection[Any, Any]
Elementwise maximum of two operands of one kind.
clamp ¶
clamp(
values: Collection[Any, Any],
lower: Collection[Any, Any] | Scalar,
upper: Collection[Any, Any] | Scalar,
) -> Collection[Any, Any]
values held between lower and upper, row by row and value
by value: min(upper, max(lower, values)). Each bound is a collection,
aligned strictly as for zk.min, or a scalar taking the values' kind
(float, int or date). A NaN stays NaN; constant bounds must be ordered.
Columns computed row by row¶
float ¶
float(
function: Callable[..., Any],
/,
*arguments: Any,
**keywords: Any,
) -> ValueExpr
A float column computed by calling function once per row, in
with_columns, with arguments and keywords resolved for that
row: a dim expression (zk.dim("mean")) gives the row's dim cell, a
value expression of a constant column (zk.value("premium")) the
row's value, and anything else is passed as it is::
rng = np.random.default_rng(seed)
zk.Collection.of(Parameters, parameters).with_columns(
gross_ibnr=zk.float(rng.lognormal, zk.dim("mean"), zk.dim("sd"), nsims)
)
The function returns a scalar for a FloatC column, a 1-D array for a
FloatA one, or a (counts, values) pair of 1-D arrays for a
FloatJ one - counts how many values each entry holds, values
all of them in turn - the same shape for every row, and arrays of one
length; ints are made floats. It's called when with_columns is, in
row order, so a generator's draws are those of one vectorised call over
the rows. Each array or jagged cell becomes an input with a tie group of
its own. An error raised by the function gets a note naming the row it
was called for.
Data already in arrays is read the same way, by a function keyed by the
dims: zk.float(lambda line: gross[line], zk.dim("line")).
Name the column with a keyword or .alias: the expression refers to
no column of its own. Shadows the builtin float when star-imported.
int ¶
int(
function: Callable[..., Any],
/,
*arguments: Any,
**keywords: Any,
) -> ValueExpr
An int column computed by calling function once per row, as
zk.float does: claims=zk.int(rng.poisson, zk.dim("frequency"), nsims).
The function returns ints, which aren't converted. Shadows the builtin
int when star-imported.