Skip to contents

Catches train/serve drift before a model scores garbage. Mirror of omop_etl.feature_contract.validate_feature_frame. Missing columns, dtype mismatches and unit suspicion (for example creatinine in umol/L) always raise; out-of-bounds values raise under on_violation = "raise", are clipped to the nearest bound under "clip" and set to NA under "nullify".

Usage

validate_feature_frame(
  df,
  feature_spec,
  on_violation = "raise",
  bounds = NULL,
  allow_extra = TRUE
)

Arguments

df

A data.frame (extra columns such as ids are allowed unless allow_extra = FALSE).

feature_spec

Spec list or path to feature_spec.json.

on_violation

"raise", "clip" or "nullify".

bounds

Optional named list of c(lo, hi) defaults.

allow_extra

If FALSE, unexpected columns are violations.

Value

An object of class feature_validation_report (a list): frame (spec-ordered, repaired features), missing, extra, dtype_mismatch, out_of_bounds, unit_suspicion, n_clipped, n_nullified, ok. On a violation that raises, the error carries the report in $report.

Details

Bounds come from the spec's bounds, then bounds, then DEFAULT_PHYSIOLOGIC_BOUNDS.