Converts character/logical columns to factors and aligns factor levels with
a training-time levels_map. Adds a dummy level when a column has only
one observed level so that downstream one-hot encoding retains a column.
.guard_ensure_levels(df, levels_map = NULL, dummy_prefix = "__dummy__")List with elements data (data.frame) and levels (named list of levels).
data.frame to normalize factor levels.
optional named list of factor levels learned from training data.
prefix used when adding a dummy level to single-level factors.