Step
Abstract base class for a feature-engineering step.
Usage
Step(
id,
default_id,
*,
keep_original_cols=None,
output_role=None,
)A step is constructed declaratively, fitted against training data to estimate and store statistics, and then applied to new data.
Everything a step needs is computed at fit time. Whatever a step has to learn from data (statistics, level sets, a basis, the list of columns to drop) is estimated once from the training data frame and stored on the step. transform() only applies that stored state; it never re-estimates anything, however different the new data looks. This is what makes a fitted recipe reproducible and free of train-to-serve skew, and it holds for every step, so individual steps do not restate it.
A step’s columns selector is resolved once, against the training data frame’s schema, when the recipe is fitted. A selector that matches nothing is not an error: the step is kept in the fitted recipe for inspection but never fitted and never run, making it the identity transform.
What a step promises about the data frame it returns is which columns are present and what they are named, not where they sit. Column position is an implementation detail that may differ between steps and backends, so downstream code should select columns by name rather than by position.
Step subclasses always run at transform time; RowOp subclasses never run on new data. There is intentionally no skip flag: whether a step runs at transform time is determined structurally by its type.
A subclass’ __init__ stores its own arguments and then calls super().__init__() to hand the framework-owned ones to the base class:
class StepMaxAbs(Step):
mode = Mode.ONE_TO_ONE
def __init__(self, columns: Selector, *, id: str | None = None):
self.columns = columns
super().__init__(id, "max_abs")See __init__ for the arguments it takes.