ExpressionCombiner

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

class ExpressionCombiner(features: Mapping[str, str] | None = None, expressions: Sequence[str] | None = None, feature_names: Sequence[str] | None = None, eps: float = 1e-08)[source]

Bases: object

Features defined by restricted arithmetic over sibling block columns.

Each formula may reference the COLUMN NAMES of the merged child blocks (e.g. T1, wash_in_slope), the injected constant eps, and the whitelisted functions abs, sqrt, square, log, log10, exp, minimum, maximum, clip. Power may be written as ** or ^.

Example:

expression(
    raw("T1"), raw("T2"),
    features={"t1_over_t2_sq": "square(T1 / (T2 ** 3 + eps))"},
)
Parameters:
  • features – Mapping of feature name to formula. Mutually exclusive with expressions.

  • expressions – Ordered formulas when names are not provided up front.

  • feature_names – Names aligned with expressions; defaults to expr_0, expr_1, …

  • eps – Value bound to the name eps inside every formula.

__init__(features: Mapping[str, str] | None = None, expressions: Sequence[str] | None = None, feature_names: Sequence[str] | None = None, eps: float = 1e-08) → None[source]
property spec: Spec

Return the algorithm specification used for provenance.

__call__(blocks: Sequence[DataFrame], *, context: Mapping[str, Any] | None = None) → DataFrame[source]

Evaluate every formula on the merged child block.

Parameters:
  • blocks – Child blocks in child order; their merged column names are the identifiers formulas may reference.

  • context – Unused by this combiner.

Returns:

One column per formula, one row per input row.

Raises:

HABITAPIError – If a formula references an unknown name or produces a non-broadcastable shape.