mostlyright.spine
mr.spine() — bring your own target frame into the leakage-guarded join.
spine(df, *, entity, decision_time, y, label_available_time=None) maps a
user-built frame into the canonical SpineContract shape (station, decision_time, label_available_time, y_*) from an explicit column mapping: the
researcher names which of their columns is the entity, which is the
point-in-time decision_time cutoff, and which are the y targets.
The mapping is never guessed, which is what keeps point-in-time integrity. A
frame missing the mapped decision_time (or entity, or a y column)
raises ContractError built by the shared _errmsg helper, so a wrong
column mapping — a label passed as decision_time, for instance — cannot slip
through silently. The user’s entity column is renamed to the canonical
station key that align() and SpineContract consume. When the
user does not map a label_available_time it defaults to decision_time,
which is conservative and non-leaking: the label is treated as known no earlier
than the decision.
The label-axis helpers (align_byo_labels / _coerce_date_column) are
reused here, so a Feast-shaped entity_df whose decision_time lives in a
datetime index is handled the same way as a user-supplied label frame.
Functions
Section titled “Functions”| Function | Description |
|---|---|
spine(df, *, entity, decision_time, y[, …]) | Map a user-built frame into the canonical spine shape. |
mostlyright.spine.spine(df, , entity, decision_time, y, label_available_time=None)
Section titled “mostlyright.spine.spine(df, , entity, decision_time, y, label_available_time=None)”Map a user-built frame into the canonical spine shape.
- Parameters:
- df (
DataFrame) – The user-built target frame. - entity (
str) – The column naming the entity (renamed to the canonicalstationkey). - decision_time (
str) – The column holding the per-row point-in-time cutoff. If it is absent as a column but lives in a datetime / date-named index, the index is lifted into a column first (reusing_coerce_date_column). - y (
str|list[str] |tuple[str,...]) – The target column name(s). A spine with no target is meaningless. - label_available_time (
str|None) – Optional column naming when the label became known — its own publication time; defaults todecision_timewhen unmapped, which is conservative and non-leaking.
- df (
- Return type:
DataFrame - Returns:
A
SpineContract-valid frame(station, decision_time, label_available_time, *y). - Raises:
ContractError – a mapped column (
entity/decision_time/ ay) is absent from the frame; the mapping is never guessed.