Building a dimension package
Hooks and helpers for packages that subclass NestedScale.
scale_alias_property
scale_alias_property(name: str) -> property
A read-only property exposing an inherited field under another name.
How a Calendar keeps timeframes and a Geoscale keeps geoframes
over the inherited frames.
scale_vocab
scale_vocab(x: NestedScale) -> dict[str, str]
The words engine messages use for this scale's dimension.
Subclasses register their own implementation with
scale_vocab.register(Subclass).
scale_payload_slice
scale_payload_slice(
x: NestedScale, i: Sequence[int]
) -> NestedScale
Subset a subclass's per-leaf payload to the kept leaftable rows i.
Called whenever the engine rebuilds an object from a row subset, with
the core fields already set to the subset and the object not yet
validated; i holds the 0-based indices of the kept rows of the
former leaftable. The method returns the object, changed with
scale_set_props(). The NestedScale default has no payload and
returns x unchanged.
scale_payload_collapse
scale_payload_collapse(
x: NestedScale, map: Sequence[int | None]
) -> NestedScale
Merge a subclass's per-leaf payload after a collapse.
The companion of scale_payload_slice() for the rebuilds that MERGE
leaves -- prune_scale(), which makes a coarser frame the leaf layer.
map has one entry per row of the FORMER leaftable: the 0-based index
of the new row that leaf was merged into, or None for a leaf that was
dropped. The object arrives with the new core fields set and not yet
validated; the method may change any field, the name of the leaf column
included, with scale_set_props(). The NestedScale default returns
x unchanged, which is right for a payload keyed by member codes.
scale_payload_parts
scale_payload_parts(x: NestedScale) -> Any
Describe the parts a subclass adds to a scale.
The seam a dimension package overrides so that scale_tree() can mark
the fields it adds and name its own verbs. The method returns a table
(or a list of dicts) with a part column and any of parent, kind,
shape, mark, verb and note. A row whose part and parent
match a part the core already lists replaces the fields it gives; any
other row is added. A top-level part is a field of the object; parent
names the field a part belongs to. mark is one of "fixed",
"derived" or "mutable". The NestedScale default adds nothing.
scale_write_payload
scale_write_payload(
x: NestedScale, dir: Path | None, header: dict
) -> dict
Write a subclass's payload in a definition; returns the header.
Called by write_scale() after the core tables are written, with the
subclass object, the bundle directory (None for a single-file
definition, which can hold inline data only) and the header so far. The
method writes its files and returns the header with its entries added
under "payload"; it may also adjust "meta" and "meta_vectors" (the
top-level meta entries the other binding reads as named vectors). The
NestedScale default returns the header unchanged.
scale_read_payload
scale_read_payload(
x: NestedScale, dir: Path | None, header: Mapping
) -> NestedScale
Rebuild a subclass from the core scale and its payload files.
Called by read_scale() with the CORE scale rebuilt from the header, the
directory the files are in and the header; dispatched on the class
registered under the header's class (see register_scale_class()),
so the method is registered for the subclass and receives a plain
NestedScale. It returns the subclass object. A scale held in meta
arrives as its reference, {"_scale": {"name", "id"}}.
register_scale_class
register_scale_class(cls: type) -> str
Register a NestedScale subclass under its pkg::Name so read_scale()
can give it back.
list_scale_classes
list_scale_classes() -> list[str]
The names of the registered classes, as <package>::<Class>, sorted:
the classes read_scale() can give back.
scale_leaf_pairs
scale_leaf_pairs(
x: NestedScale,
source: str,
target: str,
weight: str | None = None,
**kwargs: object,
) -> pa.Table
Leaf-level correspondence between two frames: columns source, target, w.
The seam a dimension package overrides (scale_leaf_pairs.register) when
its leaf layer is generated; extra identifier columns must be named in the
caller's by.
backend_bind_rows
backend_bind_rows(parts: Sequence[Table]) -> pa.Table
Row-bind tables, unifying their schemas.
backend_is_lazy
backend_is_lazy(backend: Backend) -> bool
Is this a lazy backend (pyarrow Dataset, polars LazyFrame)?
backend_of
backend_of(data: Any, arg: str = 'data') -> Backend
Classify a data argument; error when it is not a supported table.
arg is the argument name the error message uses.
backend_pull
backend_pull(table: Any) -> pa.Table
Any supported table, collected into a pyarrow.Table.
backend_restore
backend_restore(
table: Table,
backend: Backend,
collect: bool | None = None,
) -> Any
A result in the caller's type: pandas, polars, a LazyFrame (unless
collect), or a pyarrow.Table.
backend_schema
backend_schema(
data: Any, backend: Backend | None = None
) -> pa.Schema
Column names and types, without scanning a lazy input.