tanat.cast package#
Submodules#
tanat.cast.base module#
Cast primitives, structural casts, and the recipe skeleton.
- class tanat.cast.base.BaseCastRecipe[source]#
Bases:
objectCommon methods shared by sequence- and trajectory-level recipes.
Subclasses must:
be decorated with
@dataclass(frozen=True),declare
structural: StructuralCastsandfeatures: <FeatureCasts>with default factories,set
_FEATURES_CLSto the dataclass used forfeatures.
- classmethod coerce(value)[source]#
Coerce value into a recipe instance.
Accepted:
None→ default recipe.a recipe instance → returned unchanged.
a dict in the canonical nested form
{"structural": ..., "features": ...}(each side may itself be a dict, which is then unpacked into the matching dataclass).
- id_caster() Callable[[Expr], Expr] | None[source]#
Return the compiled caster for the id column, or
None.
- property id_dtype: DataType | None[source]#
Final dtype of the id recipe,
Noneif no cast is registered.
- replace(**kwargs)[source]#
Functional update.
Recognised keys:
structural=/features=: canonical nested form.id=: shortcut to reset the structuralidrecipe.time_index=: shortcut to reset the structuraltime_indexrecipe.
- property static: dict[str, list[DataType]][source]#
Per-column dtype steps of the static feature recipes.
- static_caster(col: str) Callable[[Expr], Expr] | None[source]#
Return the compiled caster for static feature col, or
None.
- structural: StructuralCasts[source]#
- class tanat.cast.base.ColumnMapCast(recipes: dict[str, list[~polars.datatypes.classes.DataType]]=<factory>)[source]#
Bases:
objectOrdered cast recipes for a named set of columns.
- append(schema: dict[str, DataType]) ColumnMapCast[source]#
Return a new map with each
col → dtypeof schema appended.
- caster(col: str) Callable[[Expr], Expr] | None[source]#
Return the compiled caster for col, or
Nonewhen unset.
- copy() ColumnMapCast[source]#
Return a deep copy of the map.
- class tanat.cast.base.ScalarCast(recipe: list[DataType] = <factory>)[source]#
Bases:
objectOrdered cast recipe for a single, well-known column.
- append(dtype: DataType) ScalarCast[source]#
Return a new recipe with dtype appended as a final step.
- caster() Callable[[Expr], Expr] | None[source]#
Return the compiled caster, or
Nonewhen the recipe is empty.
- copy() ScalarCast[source]#
Return a deep copy of the recipe.
- class tanat.cast.base.StructuralCasts(id: ScalarCast = <factory>, time_index: ScalarCast = <factory>)[source]#
Bases:
objectShared ordered casts consumed by stores: id and time index.
- __init__(id: ScalarCast = <factory>, time_index: ScalarCast = <factory>) None[source]#
- append_id(dtype: DataType) StructuralCasts[source]#
Append dtype to the id recipe; reject closed-domain dtypes.
pl.Enum/pl.Categoricalwould conflict with any id outside the current view (the store consumes the cast on the full physical data). Materialise the view viasave()first to narrow the domain.
- append_time_index(dtype: DataType) StructuralCasts[source]#
Append dtype to the time_index recipe.
- apply(lf: LazyFrame, *, id_col: str | None = None, time_cols: list[str] | None = None) LazyFrame[source]#
Apply id and (optionally) time-index structural casts to lf.
- Parameters:
lf – Input LazyFrame.
id_col – Name of the id column to cast.
None→ skip.time_cols – Names of time columns to cast.
None/[]→ skip.
- copy() StructuralCasts[source]#
Return a deep copy of the structural casts.
- id_caster() Callable[[Expr], Expr] | None[source]#
Return the compiled caster for the id column, or
None.
- time_index: ScalarCast[source]#
- tanat.cast.base.apply_cast_exprs(lf: LazyFrame, exprs: list[Expr]) LazyFrame[source]#
Apply pre-built cast expressions to lf.
Returns lf unchanged when exprs is empty.
- tanat.cast.base.build_caster(recipe: list[DataType]) Callable[[Expr], Expr][source]#
Build an expression caster from an ordered dtype recipe.
- tanat.cast.base.probe_cast_recipe(lf: LazyFrame, recipes: dict[str, list[DataType]], n_rows: int = 10) None[source]#
Validate multi-step cast recipes on a small sample of lf.
Each column is cast through its recipe in order (
T0 → T1 → … → Tn). Absent columns are silently skipped.- Raises:
TypeError – If any step fails, with column name and full chain in the message.
tanat.cast.sequence module#
Sequence-level cast recipes.
- class tanat.cast.sequence.SequenceCastRecipe(structural: StructuralCasts = <factory>, features: SequenceFeatureCasts = <factory>)[source]#
Bases:
BaseCastRecipeType-cast overrides for a sequence view.
- __init__(structural: StructuralCasts = <factory>, features: SequenceFeatureCasts = <factory>) None[source]#
- append(*, id: DataType | None = None, time_index: DataType | None = None, entity: dict[str, DataType] | None = None, static: dict[str, DataType] | None = None) SequenceCastRecipe[source]#
Return a new recipe extended with the given structural and feature casts.
- property entity: dict[str, list[DataType]][source]#
Per-column dtype steps of the entity feature recipes.
- entity_caster(col: str) Callable[[Expr], Expr] | None[source]#
Return the compiled caster for entity feature col, or
None.
- feature_exprs(is_static: bool = False) list[Expr][source]#
Return the
with_columnsexpressions for entity or static features.
- features: SequenceFeatureCasts[source]#
- fork_casts(*, feature_col: str | None = None, static_col: str | None = None) _ForkCasts[source]#
Return precompiled casts for a fork operation.
- structural: StructuralCasts[source]#
- class tanat.cast.sequence.SequenceFeatureCasts(entity: ColumnMapCast = <factory>, static: ColumnMapCast = <factory>)[source]#
Bases:
objectFeature casts consumed by sequence views.
- __init__(entity: ColumnMapCast = <factory>, static: ColumnMapCast = <factory>) None[source]#
- apply(lf: LazyFrame, *, is_static: bool) LazyFrame[source]#
Apply entity or static feature casts to lf (no-op when empty).
- copy() SequenceFeatureCasts[source]#
Return a deep copy of the feature casts.
- entity: ColumnMapCast[source]#
- probe(view, *, is_static: bool) None[source]#
Probe this candidate recipe on top of the current sequence view.
- probe_lf(lf: LazyFrame | None, *, is_static: bool) None[source]#
Force-evaluate the selected bucket on a view LazyFrame.
- static: ColumnMapCast[source]#
tanat.cast.trajectory module#
Trajectory-level cast recipes.
- class tanat.cast.trajectory.TrajectoryCastRecipe(structural: StructuralCasts = <factory>, features: TrajectoryFeatureCasts = <factory>)[source]#
Bases:
BaseCastRecipeType-cast overrides for a trajectory view.
Entity-level feature casts live in the trajectory’s sub-pools (see
SequenceCastRecipe); at the trajectory layer onlystaticfeatures are observable directly.- __init__(structural: StructuralCasts = <factory>, features: TrajectoryFeatureCasts = <factory>) None[source]#
- append(*, id: DataType | None = None, time_index: DataType | None = None, static: dict[str, DataType] | None = None) TrajectoryCastRecipe[source]#
Return a new recipe extended with the given structural and static casts.
- features: TrajectoryFeatureCasts[source]#
- structural: StructuralCasts[source]#
- class tanat.cast.trajectory.TrajectoryFeatureCasts(static: ColumnMapCast = <factory>)[source]#
Bases:
objectFeature casts consumed by trajectory views (static only).
- __init__(static: ColumnMapCast = <factory>) None[source]#
- copy() TrajectoryFeatureCasts[source]#
Return a deep copy of the feature casts.
- static: ColumnMapCast[source]#
Module contents#
Cast recipes and reusable cast primitives.
- class tanat.cast.ColumnMapCast(recipes: dict[str, list[~polars.datatypes.classes.DataType]]=<factory>)[source]#
Bases:
objectOrdered cast recipes for a named set of columns.
- append(schema: dict[str, DataType]) ColumnMapCast[source]#
Return a new map with each
col → dtypeof schema appended.
- caster(col: str) Callable[[Expr], Expr] | None[source]#
Return the compiled caster for col, or
Nonewhen unset.
- copy() ColumnMapCast[source]#
Return a deep copy of the map.
- class tanat.cast.ScalarCast(recipe: list[DataType] = <factory>)[source]#
Bases:
objectOrdered cast recipe for a single, well-known column.
- append(dtype: DataType) ScalarCast[source]#
Return a new recipe with dtype appended as a final step.
- caster() Callable[[Expr], Expr] | None[source]#
Return the compiled caster, or
Nonewhen the recipe is empty.
- copy() ScalarCast[source]#
Return a deep copy of the recipe.
- class tanat.cast.SequenceCastRecipe(structural: StructuralCasts = <factory>, features: SequenceFeatureCasts = <factory>)[source]#
Bases:
BaseCastRecipeType-cast overrides for a sequence view.
- __init__(structural: StructuralCasts = <factory>, features: SequenceFeatureCasts = <factory>) None[source]#
- append(*, id: DataType | None = None, time_index: DataType | None = None, entity: dict[str, DataType] | None = None, static: dict[str, DataType] | None = None) SequenceCastRecipe[source]#
Return a new recipe extended with the given structural and feature casts.
- property entity: dict[str, list[DataType]][source]#
Per-column dtype steps of the entity feature recipes.
- entity_caster(col: str) Callable[[Expr], Expr] | None[source]#
Return the compiled caster for entity feature col, or
None.
- feature_exprs(is_static: bool = False) list[Expr][source]#
Return the
with_columnsexpressions for entity or static features.
- features: SequenceFeatureCasts[source]#
- fork_casts(*, feature_col: str | None = None, static_col: str | None = None) _ForkCasts[source]#
Return precompiled casts for a fork operation.
- structural: StructuralCasts[source]#
- class tanat.cast.SequenceFeatureCasts(entity: ColumnMapCast = <factory>, static: ColumnMapCast = <factory>)[source]#
Bases:
objectFeature casts consumed by sequence views.
- __init__(entity: ColumnMapCast = <factory>, static: ColumnMapCast = <factory>) None[source]#
- apply(lf: LazyFrame, *, is_static: bool) LazyFrame[source]#
Apply entity or static feature casts to lf (no-op when empty).
- copy() SequenceFeatureCasts[source]#
Return a deep copy of the feature casts.
- entity: ColumnMapCast[source]#
- probe(view, *, is_static: bool) None[source]#
Probe this candidate recipe on top of the current sequence view.
- probe_lf(lf: LazyFrame | None, *, is_static: bool) None[source]#
Force-evaluate the selected bucket on a view LazyFrame.
- static: ColumnMapCast[source]#
- class tanat.cast.StructuralCasts(id: ScalarCast = <factory>, time_index: ScalarCast = <factory>)[source]#
Bases:
objectShared ordered casts consumed by stores: id and time index.
- __init__(id: ScalarCast = <factory>, time_index: ScalarCast = <factory>) None[source]#
- append_id(dtype: DataType) StructuralCasts[source]#
Append dtype to the id recipe; reject closed-domain dtypes.
pl.Enum/pl.Categoricalwould conflict with any id outside the current view (the store consumes the cast on the full physical data). Materialise the view viasave()first to narrow the domain.
- append_time_index(dtype: DataType) StructuralCasts[source]#
Append dtype to the time_index recipe.
- apply(lf: LazyFrame, *, id_col: str | None = None, time_cols: list[str] | None = None) LazyFrame[source]#
Apply id and (optionally) time-index structural casts to lf.
- Parameters:
lf – Input LazyFrame.
id_col – Name of the id column to cast.
None→ skip.time_cols – Names of time columns to cast.
None/[]→ skip.
- copy() StructuralCasts[source]#
Return a deep copy of the structural casts.
- id_caster() Callable[[Expr], Expr] | None[source]#
Return the compiled caster for the id column, or
None.
- time_index: ScalarCast[source]#
- class tanat.cast.TrajectoryCastRecipe(structural: StructuralCasts = <factory>, features: TrajectoryFeatureCasts = <factory>)[source]#
Bases:
BaseCastRecipeType-cast overrides for a trajectory view.
Entity-level feature casts live in the trajectory’s sub-pools (see
SequenceCastRecipe); at the trajectory layer onlystaticfeatures are observable directly.- __init__(structural: StructuralCasts = <factory>, features: TrajectoryFeatureCasts = <factory>) None[source]#
- append(*, id: DataType | None = None, time_index: DataType | None = None, static: dict[str, DataType] | None = None) TrajectoryCastRecipe[source]#
Return a new recipe extended with the given structural and static casts.
- features: TrajectoryFeatureCasts[source]#
- structural: StructuralCasts[source]#
- class tanat.cast.TrajectoryFeatureCasts(static: ColumnMapCast = <factory>)[source]#
Bases:
objectFeature casts consumed by trajectory views (static only).
- __init__(static: ColumnMapCast = <factory>) None[source]#
- copy() TrajectoryFeatureCasts[source]#
Return a deep copy of the feature casts.
- static: ColumnMapCast[source]#
- tanat.cast.apply_cast_exprs(lf: LazyFrame, exprs: list[Expr]) LazyFrame[source]#
Apply pre-built cast expressions to lf.
Returns lf unchanged when exprs is empty.
- tanat.cast.probe_cast_recipe(lf: LazyFrame, recipes: dict[str, list[DataType]], n_rows: int = 10) None[source]#
Validate multi-step cast recipes on a small sample of lf.
Each column is cast through its recipe in order (
T0 → T1 → … → Tn). Absent columns are silently skipped.- Raises:
TypeError – If any step fails, with column name and full chain in the message.