Skip to content

v0.6.0

Latest

Choose a tag to compare

@github-actions github-actions released this 10 Nov 09:49
· 85 commits to main since this release

Milestone: v0.6.0 - Pipeline Composition & Automation

Added

  • AutoPipeline in src/automation/auto_pipeline.rs builds a complete
    preprocessing Pipeline from a DataFrame's inferred schema and exposes it
    through prepared_pipeline(), so the inferred plan can be reviewed before it
    is applied. fit drops all-null columns, removes constant columns (when
    configured), expands datetime components, optionally trims and collapses
    string whitespace, groups rare categories, one-hot encodes low-cardinality
    strings, hashes high-cardinality strings (or target-encodes them for a binary
    classification target), and imputes and scales Float64 columns when
    AutoImputerConfig / AutoScalerConfig are supplied. Unseen one-hot
    categories are ignored by default so new data can be scored;
    AutoPipelineConfig::handle_unknown restores the strict behaviour. AutoPipelineConfig
    carries every threshold and toggle, from_inferred_schema derives a sensible
    default plan from the frame, and transform validates the input against the
    schema frozen at fit time and drops the target column. AutoPipeline and its
    config types are exported from the prelude (#85).

  • FeatureNamesOut in src/traits/output_names.rs reports the columns a
    fitted transformer's transform emits, as metadata, without materialising a
    frame. The trait is implemented by every transformer: pass-through and
    in-place transformers return their input names, selectors return the learned
    subset, and generators (encoders, interactions, lags, rolling windows, date
    and text features, …) append the exact names they create. Calling it before
    fit returns Error::NotFitted. FeatureNamesOut is now a supertrait of
    DataFrameTransformer, so Pipeline::feature_names_out threads names through
    every step, and ColumnTransformer, FeatureUnion, ConditionalPipeline,
    and CachedPipeline aggregate their children in the same order their
    transform stacks them (#83). Custom DataFrameTransformer implementations
    inherit an identity default, so they keep compiling, and should override it
    when their transform drops, renames, or generates columns.

  • InverseTransform<X> in src/traits/inverse.rs reverses an invertible
    transformer: inverse_transform maps data from the transformer's output space
    back to its input space, so predictions can be read in original units and a
    step can be checked with inverse_transform(transform(x)) ≈ x. It is
    implemented by StandardScaler (x * std + mean), MinMaxScaler
    ((x - range_min) / scale + min, extrapolating outside the fitted range),
    RobustScaler (x * scale + center), MaxAbsScaler (x * max_abs),
    LogTransformer (exp, expm1, 2^y, 10^y, b^y per LogMethod),
    PowerTransformer (Box-Cox and Yeo-Johnson inverses plus the undo of the
    optional standardization) and QuantileTransformer (interpolation on the
    stored reference grid). Calling inverse_transform before fit returns
    Error::NotFitted; a value outside the fitted transform's range — one whose
    inverse base would be non-positive for Box-Cox or Yeo-Johnson — returns
    Error::InvalidInput. HasInverse::is_invertible reports the capability for
    each of them. Composition-level inverses (Pipeline, ColumnTransformer,
    FeatureUnion) are not included: those steps are type-erased to
    Box<dyn DataFrameTransformer> and cannot forward inverse_transform without
    changing their public construction API (#84).

  • CachedPipeline in src/pipeline/cached_pipeline.rs wraps a Pipeline and
    caches every step's output, so transforming an input the cache has already
    seen replays the stored frames instead of re-running the steps. The cache key
    is a fingerprint of the input schema (column names + dtypes) and row count —
    cheap to compute on every call, but blind to values, so any other frame of the
    same shape and height hits the entry too and clear_cache() is required
    before transforming one. Up to
    max_cache_entries inputs are remembered (16 by default) with FIFO eviction;
    0 disables caching entirely. cache_size() reports the current count, a
    re-fit clears the cache, and the wrapper's output always matches the wrapped
    Pipeline::transform for the input it was computed from (#75).

  • ConditionalPipeline in src/pipeline/conditional_pipeline.rs routes each
    column to a transformer by [ColumnPredicate]: dtype (IsFloat64, IsInt,
    IsString, IsDatetime, IsBoolean), a regex on the column name
    (NameMatches), or a user closure (Custom). Rules are tried in declaration
    order and the first match claims the column, so a column is transformed once
    and never duplicated; columns no rule claims go to the optional fallback
    transformer or are dropped. Each transformer receives only its own columns.

  • DataQualityReport in src/automation/data_quality_report.rs summarises a
    frame before modelling: per-column nulls, NaN and ±Inf counts, unique
    counts and cardinality buckets, Float64 moments
    (mean/std/min/max/median/skew/kurtosis), IQR, Z-score and MAD outlier counts,
    string length and mode stats, plus frame-level duplicated rows, duplicated
    columns and constant columns. It also emits Recommendations (drop, impute,
    scale, encode, remove duplicates) so AutoPipeline can consume the same
    heuristics. Diagnostic, not a transformer: no fitted state, the input frame is
    never modified. print_summary and to_markdown render the report; to_json
    waits on the optional serde feature (issue #28).

  • SchemaValidator foundation in src/traits/schema.rs: a transformer can now
    describe the input it needs with SchemaSpec / ColumnRequirement
    (Named, Dtype { min_count }, NameOnly) via the new RequiresSchema
    trait, and validate_schema(&spec, &df) reports every unmet requirement in one
    InvalidInput error (Missing column …, Dtype mismatch on …,
    Require >= N Float64 columns, found M) instead of failing late inside Polars.
    Validation is schema-only, so a null-only column still satisfies a dtype
    requirement. Once a transformer is fitted its spec names the columns it
    learned, so a frame carrying the right dtypes under different names is
    rejected up front rather than failing inside transform. StandardScaler,
    MinMaxScaler, RobustScaler, Binarizer, OneHotEncoder and
    VarianceThreshold implement RequiresSchema (#82).

  • AutoScaler in src/preprocessing/auto_scaler.rs picks a scaling strategy
    per Float64 column from the column's own statistics instead of making the
    caller choose between StandardScaler, MinMaxScaler, RobustScaler,
    MaxAbsScaler and PowerTransformer. fit inspects each column and
    delegates to a ColumnTransformer that runs one chosen scaler per strategy
    subset, so a frame mixing an outlier-heavy column and a near-Gaussian one is
    handled in a single pass. The heuristic order is most-specific-first:

    50% exact zeros → MaxAbsScaler; negligible variance → MaxAbsScaler (the
    only delegate that accepts a constant column); max|x - median| / IQR > 10 →
    RobustScaler; |skew| > 1 → PowerTransformer; raw kurtosis < 2 →
    MinMaxScaler; otherwise StandardScaler. ScalingStrategy::Auto is the
    default and strategy(...) forces a single scaler for every column;
    chosen_name() and column_types() expose the selection (#86).

  • AutoImputer in src/preprocessing/auto_imputer.rs picks an imputation
    strategy per Float64 column from the column's missing-value pattern and
    distribution instead of making the caller choose between Mean, Median,
    MostFrequent and Constant. fit skips columns with no missing value,
    follows NullColumnBehavior for an entirely null column (Drop by default,
    plus Error and Fill), leaves a column at or above
    high_null_threshold (default 0.5) unchanged, and otherwise picks
    Median when |skewness| > skew_threshold (default 1.0) and Mean
    otherwise. Delegation runs through a ColumnTransformer with one
    SimpleImputer per strategy subset, so a frame mixing a near-Gaussian
    column, a skewed one and a String column is handled in a single pass;
    force_strategy(...) replaces the heuristic, and chosen_name() and
    column_types() expose the selection (#87).

Fixed

  • FeatureUnion::fit now rejects a DataFrame with 0 columns with
    Error::InvalidInput, matching ColumnTransformer and
    ConditionalPipeline, instead of fitting and failing later at transform
    with "produced no output columns" (#253).
  • RollingAggregator::fit and Difference::fit now reject configured columns
    that are not Float64 with Error::InvalidInput, instead of reporting the
    transformer fitted and failing later at transform. Frames that previously
    fit with a String or integer configured column now hard-error; cast those
    columns before fitting (#221).
  • PolynomialFeatures.transform now carries columns of other dtypes (an
    identifier, a label) through unchanged, after the generated features.
    Previously it returned only the generated features,
    so [a (f64), label (str)] came back as [a, a^] with the label silently
    dropped. A carried-through column whose name equals a generated one is
    rejected with Error::InvalidInput (at fit, and at transform for a
    column that only appears then) (#207).
  • MissingIndicator now rejects generated indicator column names that collide
    with existing input columns or other planned indicator columns, returning
    Error::InvalidInput at fit and transform instead of silently
    overwriting user columns with Polars' with_column (#196).
  • AutoTypeDetector::transform now preserves original column ordering instead
    of hoisting one-hot and feature-hashed columns ahead of numeric pass-through
    columns. Output columns follow the fitted DataFrame column order, with encoded
    expansions replacing categorical and high-cardinality columns in-place (#205).
  • LogTransformer::method, columns and check_positive now clear the fitted
    state when called after fit, so the transformer must be refit, matching
    PowerTransformer's builders. Previously method kept the fit: fitting
    Log1p on [0, 1, 2] and then switching to Ln transformed to
    [-inf, 0, 0.693] without an error, and inverse_transform used the new
    method too. transform and inverse_transform now return Error::NotFitted
    until the refit, which re-runs the domain check for the new method (#208).
  • KBinsDiscretizer.fit (one-hot modes) and PolynomialFeatures.fit now
    reject generated output names that collide, returning Error::InvalidInput
    instead of fitting and then failing every transform with a duplicate-column
    error. For KBinsDiscretizer that is a {column}_bin_{j} name equal to a
    column passed through unchanged; for PolynomialFeatures it is two terms
    with the same name, such as an input column a_b_inter next to the a * b
    interaction. Because term names do not encode exponents, PolynomialFeatures
    with degree >= 3 and interaction_only(false) always produces such a
    collision (a^2 and a^3 are both named a^) and now fails at fit
    instead of at transform (#209).
  • Binarizer now rejects input frames with no Float64 column at both fit
    and transform time using the shared require_f64_columns check, so strings
    and dates no longer pass through unchanged and silently leak their dtype to
    downstream steps. The error matches what every sibling numeric transformer
    already emits. Non-Float64 columns accompanying at least one Float64
    column keep their pass-through behaviour (#182). Frames that previously fit
    and transformed successfully because they held no Float64 column at all
    now hard-error; cast them before fitting.
  • QuantileTransformer no longer treats a column with genuine but tiny spread
    as constant. The degeneracy guard used an absolute f64::EPSILON threshold,
    so any column whose range was below ~2.2e-16 (for example
    [1e-300, 2e-300, 3e-300, 4e-300, 5e-300]) collapsed to the constant
    mid-value 0.5 and silently dropped the feature's information. The guard is
    now degenerate only when the endpoints are equal, so such a column ranks as
    [0, 0.25, 0.5, 0.75, 1], while a genuinely constant column (including an
    all-zero one) keeps its documented 0.5 (#180).
  • StringCleaner.fit now validates each replacement template against the
    pattern it runs on and returns Error::InvalidInput naming the bad
    template, instead of passing it through to transform, where the regex
    crate expands a reference to a nonexistent capture group into an empty
    string and silently blanks every matched cell. A template such as
    .replace("[a-z]", "$1") — $1 on a pattern without capture groups — or
    a ${name} reference to an undefined group is now rejected at fit.
    Valid templates are unaffected: $0 (the whole match), in-range numbered
    references, references to groups the pattern does define, and the $$
    escape for a literal dollar sign all still fit and expand as before (#288).