ump_workflow.profile
module ump-workflow
The pandas side of ump_spec.rules.check_input: build the FrameProfile it reads, infer a contract from a
training frame, and apply an InputReport to a frame (moved here from babelfin’s _contract.py so the runtime
checks contracts without babelfin).
Category level values never leave the frame: a level set is a sha256 of the sorted values, a count and a sha256
per level (so a check can name the rows at a new level for clean_frame to exclude without the contract holding
the values).
Functions
Section titled “Functions”dtype_family
Section titled “dtype_family”function
def dtype_family(dtype: Any) -> strA dtype’s family: bool, int, float, datetime, string (object, str, category) or its own name.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 35
cast_result
Section titled “cast_result”function
def cast_result(s: pd.Series, dtype: str) -> CastResultCan s become dtype? exact (same family), coerced (safe cast) or failed.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 52
apply_cast
Section titled “apply_cast”function
def apply_cast(s: pd.Series, dtype: str) -> pd.SeriesCast s to dtype (a cast cast_result called coerced).
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 73
level_hash
Section titled “level_hash”function
def level_hash(value: Any) -> strsha256 (hex) of one level’s canonical JSON string.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 94
level_set
Section titled “level_set”function
def level_set(s: pd.Series) -> LevelSetsha256 (hex) of the canonical JSON of the sorted unique non-null values as strings, their count, and the sorted sha256 of each level. Never the values.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 99
to_times
Section titled “to_times”function
def to_times(s: pd.Series) -> pd.SeriesThe column as datetimes (strings parsed; unparseable values become NaT).
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 116
time_profile
Section titled “time_profile”function
def time_profile(s: pd.Series, freq: str | None) -> TimeProfile | NoneRange, distinct steps, repeats, regularity at freq and missing steps of a time column.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 122
profile_frame
Section titled “profile_frame”function
def profile_frame(contract: InputContract, df: pd.DataFrame) -> FrameProfileWhat check_input reads about df: no row values, only dtypes, counts and hashes.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 146
clean_frame
Section titled “clean_frame”function
def clean_frame(report: InputReport, df: pd.DataFrame) -> pd.DataFrameA new frame with the excluded rows removed (rows at a new category level, matched by level hash, and rows
with no time or category value), drop_columns dropped and the coerce casts applied. The input is not
changed. Missing values in variables are left for the caller’s stated policy.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 166
contract_from_frame
Section titled “contract_from_frame”function
def contract_from_frame( df: pd.DataFrame, *, time: str | None, target: str | None, freq: str | None = None, categories: dict[str, DimPolicy] | list[str] | None = None, extra: Literal['allow', 'drop'] = 'drop', min_rows: int | None = None,) -> InputContractInfer a contract from a training frame: every non-time, non-target, non-category column is a required
variable with the frame’s dtype (missing: forbid unless it already has nulls). categories maps a
column to its policy (a list means fixed); when None, string columns are fixed categories. Fixed
categories get their level set (hash and count). freq is inferred from the time column when not given.
Source: packages/ump-workflow/src/ump_workflow/profile.py, line 185
Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
DimPolicy | Literal['fixed', 'extend', 'new_levels'] |