ump_spec.rules.contract
module ump-spec
Check new input against a workflow’s InputContract (feature workflow-bundles S3).
check_input reads a FrameProfile (built by the caller, babelfin with pandas) and never the rows. Rules,
reported in this order:
- every required var, the time column, every categorical dim and every explicit
keycolumn is a column (exact names, order free), elseINPUT_REQUIRED_MISSING(refuse); the target is required only to refit. An optional var that is absent givesINPUT_OPTIONAL_MISSING(warn). - the caller’s cast result to the contract dtype (the time column’s is
TIME_DTYPE; on a refit the target’s istarget_dtypeand it counts as required):coercedgivesINPUT_DTYPE_COERCED(warn, column listed incoerce);failedgivesINPUT_DTYPE_FAILED, refuse on a required column, warn on an optional var (the optional column is listed indrop_columns). - a var with
missing: forbidand nulls (and, on a refit, a target with nulls) givesINPUT_MISSING_VALUES(warn; the caller drops or fills per its policy, never silently). Nulls in the time column, a categorical dim or an explicit key column giveINPUT_MISSING_VALUES(exclude): a row with no time or category cannot be placed, so those rows are excluded (the column is listed inexclude_nulls). - duplicate keys give
INPUT_DUPLICATE_KEYS(refuse). - a time dim with policy
extendthat is not regular or has gaps givesINPUT_IRREGULAR_TIME(warn; a score routes to refit). - a fixed categorical dim whose level set differs from the trained one. With per-level hashes on both sides, levels
not trained give
NEW_LEVEL_EXCLUDED(exclude; their hashes are listed inexclude_levelsso the caller drops those rows), and trained levels that are absent giveINPUT_LEVELS_CHANGED(warn). Without per-level hashes (a contract written before them) only the set hash and count are compared: more levels than trained givesNEW_LEVEL_EXCLUDEDwith nothing listed (the rows cannot be picked out), any other differenceINPUT_LEVELS_CHANGED. - fewer rows than
min_rows(proposed) givesINPUT_BELOW_MIN_ROWS(warn). - columns the contract does not name (vars, dims, time, target, key):
extra: dropgivesINPUT_EXTRA_DROPPED(info, listed indrop_columns);allowpasses them silently.
Score continuity (mode score with a time column and history_end): the new input must start one step after
the history ends. Frequencies W and W-<DAY> are seven days, D one day; any other gives
INPUT_HISTORY_UNCHECKED. Starting on or before the history end is INPUT_HISTORY_OVERLAP, later than one step
after it INPUT_HISTORY_GAP. All three warn and route to refit. Refit mode adds INPUT_ROWS_GREW (info) when
there are more rows than the workflow was trained on.
The route is not_available when any note refuses, refit in refit mode or when a note routes there, else
score.
Functions
Section titled “Functions”input_key
Section titled “input_key”function
def input_key(contract: InputContract) -> list[str]The columns that identify a row: the contract’s key, or the time column plus the categorical dims.
Source: packages/ump-spec/src/ump_spec/rules/contract.py, line 65
freq_days
Section titled “freq_days”function
def freq_days(freq: str | None) -> int | NoneDays per step for the frequencies the continuity check understands (W, W-<DAY>, D), else
None.
Source: packages/ump-spec/src/ump_spec/rules/contract.py, line 74
check_input
Section titled “check_input”function
def check_input( contract: InputContract, profile: FrameProfile, *, mode: InputMode = 'score', history_end: str | None = None, trained_rows: int | None = None,) -> InputReportCheck a frame’s profile against contract; see the module docstring for the rules and their order.
Source: packages/ump-spec/src/ump_spec/rules/contract.py, line 91
Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
REFIT_CODES | frozenset[str] | frozenset({'INPUT_IRREGULAR_TIME', 'INPUT_HISTORY_GAP', 'INPUT_HISTORY_OVERLA... | Note codes that send a score to refit. |
TIME_DTYPE | 'datetime64[ns]' | The dtype the time column is cast to. |