Skip to content

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).

function

def dtype_family(dtype: Any) -> str

A 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

function

def cast_result(s: pd.Series, dtype: str) -> CastResult

Can s become dtype? exact (same family), coerced (safe cast) or failed.

Source: packages/ump-workflow/src/ump_workflow/profile.py, line 52

function

def apply_cast(s: pd.Series, dtype: str) -> pd.Series

Cast s to dtype (a cast cast_result called coerced).

Source: packages/ump-workflow/src/ump_workflow/profile.py, line 73

function

def level_hash(value: Any) -> str

sha256 (hex) of one level’s canonical JSON string.

Source: packages/ump-workflow/src/ump_workflow/profile.py, line 94

function

def level_set(s: pd.Series) -> LevelSet

sha256 (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

function

def to_times(s: pd.Series) -> pd.Series

The column as datetimes (strings parsed; unparseable values become NaT).

Source: packages/ump-workflow/src/ump_workflow/profile.py, line 116

function

def time_profile(s: pd.Series, freq: str | None) -> TimeProfile | None

Range, distinct steps, repeats, regularity at freq and missing steps of a time column.

Source: packages/ump-workflow/src/ump_workflow/profile.py, line 122

function

def profile_frame(contract: InputContract, df: pd.DataFrame) -> FrameProfile

What check_input reads about df: no row values, only dtypes, counts and hashes.

Source: packages/ump-workflow/src/ump_workflow/profile.py, line 146

function

def clean_frame(report: InputReport, df: pd.DataFrame) -> pd.DataFrame

A 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

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,
) -> InputContract

Infer 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

NameTypeValueDescription
DimPolicyLiteral['fixed', 'extend', 'new_levels']