"""Feature engineering: the only copy. Training imports it, and train.log_and_register ships this package inside the logged pyfunc (code_paths), so serving runs exactly this code on the raw columns below. """ import pandas as pd # What serving must send: raw values as stored in the variants table / its annotations. RAW_COLUMNS = ["impact", "consequence", "gnomad_af", "cadd_phred", "am_pathogenicity"] IMPACT_ORDER = {"MODIFIER": 0, "LOW": 1, "MODERATE": 2, "HIGH": 3} def build(df: pd.DataFrame) -> pd.DataFrame: out = pd.DataFrame(index=df.index) out["impact_rank"] = df["impact"].map(IMPACT_ORDER).fillna(0).astype(int) # No gnomAD record means the variant was not observed: treat as AF 0. out["gnomad_af"] = pd.to_numeric(df["gnomad_af"], errors="coerce").fillna(0.0) out["cadd_phred"] = pd.to_numeric(df["cadd_phred"], errors="coerce") out["am_pathogenicity"] = pd.to_numeric(df["am_pathogenicity"], errors="coerce") out["consequence"] = df["consequence"].astype("category") return out