sklink.primitives
Aggregation primitives: what an expression computes over related rows.
Classes:
- KernelContext: Extra information a kernel may need besides the rows it aggregates.
- Primitive: Description of an aggregation primitive.
Functions:
- default_primitives: Primitives generated by default for a column of the given semantic type.
- get_kernel: Return the implementation of a primitive for a backend (NumPy fallback).
- get_primitive: Return a registered primitive by name.
- list_primitives: Names of the registered primitives, sorted.
- register_primitive: Register a primitive and its implementation per backend.
sklink.primitives.KernelContext
KernelContext(all_group: np.ndarray, cutoff_seconds: np.ndarray | None = None, row_seconds: np.ndarray | None = None) -> NoneExtra information a kernel may need besides the rows it aggregates.
Attributes:
- all_group (
ndarray): Group of every reached row before thewhereconditions. - cutoff_seconds (
ndarray | None): Cutoff of every group in seconds since the epoch, in temporal mode. - row_seconds (
ndarray | None): Time of every aggregated row in seconds since the epoch, aligned with
sklink.primitives.KernelContext.all_group
all_group: np.ndarrayGroup of every reached row before the where conditions.
sklink.primitives.KernelContext.cutoff_seconds
cutoff_seconds: np.ndarray | None = NoneCutoff of every group in seconds since the epoch, in temporal mode.
sklink.primitives.KernelContext.row_seconds
row_seconds: np.ndarray | None = NoneTime of every aggregated row in seconds since the epoch, aligned with group (and values); given in temporal mode to primitives with requires_time on a table with a time column, None otherwise.
sklink.primitives.Primitive
Primitive(name: str, input_types: frozenset[str], output_type: str, empty_value: Literal['zero', 'false', 'missing'], decomposable: bool, requires_time: bool = False, params: tuple[str, ...] = (), needs_where: bool = False) -> NoneDescription of an aggregation primitive.
Guides: Custom primitives
Parameters:
- name (
str): Lowercase identifier used in canonical names. - input_types (
frozenset of str): Semantic types of the aggregated column it accepts, or{"rows"}for primitives that work on rows without a column (count). - output_type (
str): Semantic type of the result, or"same"for the input type. - empty_value (
(zero, false, missing)): Result when no row is reached. - decomposable (
bool): Whether it can be computed from cumulative sums; only those are combined with learned conditions by relational trees. - requires_time (
bool): Whether it needs temporal mode. - params (
tuple of str): Names of the parameters it takes, such as("q",). - needs_where (
bool): Whether it is meaningless without conditions (proportion).
Functions:
- result_type: Semantic type of the output for a given input type.
Attributes:
- decomposable (
bool): - empty_value (
Literal['zero', 'false', 'missing']): - input_types (
frozenset[str]): - name (
str): - needs_where (
bool): - output_type (
str): - params (
tuple[str, ...]): - requires_time (
bool): - takes_column (
bool): Whether the primitive aggregates a column rather than counting rows.
sklink.primitives.Primitive.decomposable
decomposable: boolsklink.primitives.Primitive.empty_value
empty_value: Literal['zero', 'false', 'missing']sklink.primitives.Primitive.input_types
input_types: frozenset[str]sklink.primitives.Primitive.name
name: strsklink.primitives.Primitive.needs_where
needs_where: bool = Falsesklink.primitives.Primitive.output_type
output_type: strsklink.primitives.Primitive.params
params: tuple[str, ...] = ()sklink.primitives.Primitive.requires_time
requires_time: bool = Falsesklink.primitives.Primitive.result_type
result_type(input_type: str | None) -> strSemantic type of the output for a given input type.
sklink.primitives.Primitive.takes_column
takes_column: boolWhether the primitive aggregates a column rather than counting rows.
sklink.primitives.default_primitives
default_primitives(input_type: str) -> tuple[str, ...]Primitives generated by default for a column of the given semantic type.
"rows" gives the row primitives. Primitives that require time (time_since_*, last and trend) are used only in temporal mode and on tables with a time column; the caller drops them otherwise.
sklink.primitives.get_kernel
get_kernel(name: str, backend: str = 'numpy') -> KernelReturn the implementation of a primitive for a backend (NumPy fallback).
sklink.primitives.get_primitive
get_primitive(name: str) -> PrimitiveReturn a registered primitive by name.
sklink.primitives.list_primitives
list_primitives() -> list[str]Names of the registered primitives, sorted.
sklink.primitives.register_primitive
register_primitive(primitive: Primitive, *, backends: Mapping[str, Kernel], overwrite: bool = False) -> NoneRegister a primitive and its implementation per backend.
Guides: Custom primitives
Parameters: