Repository navigation
Milestone: v0.6.0 - Pipeline Composition & Automation
Added
-
AutoPipelineinsrc/automation/auto_pipeline.rsbuilds a complete
preprocessingPipelinefrom aDataFrame's inferred schema and exposes it
throughprepared_pipeline(), so the inferred plan can be reviewed before it
is applied.fitdrops 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 scalesFloat64columns when
AutoImputerConfig/AutoScalerConfigare supplied. Unseen one-hot
categories are ignored by default so new data can be scored;
AutoPipelineConfig::handle_unknownrestores the strict behaviour.AutoPipelineConfig
carries every threshold and toggle,from_inferred_schemaderives a sensible
default plan from the frame, andtransformvalidates the input against the
schema frozen at fit time and drops the target column.AutoPipelineand its
config types are exported from the prelude (#85). -
FeatureNamesOutinsrc/traits/output_names.rsreports the columns a
fitted transformer'stransformemits, 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
fitreturnsError::NotFitted.FeatureNamesOutis now a supertrait of
DataFrameTransformer, soPipeline::feature_names_outthreads names through
every step, andColumnTransformer,FeatureUnion,ConditionalPipeline,
andCachedPipelineaggregate their children in the same order their
transformstacks them (#83). CustomDataFrameTransformerimplementations
inherit an identity default, so they keep compiling, and should override it
when theirtransformdrops, renames, or generates columns. -
InverseTransform<X>insrc/traits/inverse.rsreverses an invertible
transformer:inverse_transformmaps 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 withinverse_transform(transform(x)) ≈ x. It is
implemented byStandardScaler(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^yperLogMethod),
PowerTransformer(Box-Cox and Yeo-Johnson inverses plus the undo of the
optional standardization) andQuantileTransformer(interpolation on the
stored reference grid). Callinginverse_transformbeforefitreturns
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_invertiblereports 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 forwardinverse_transformwithout
changing their public construction API (#84). -
CachedPipelineinsrc/pipeline/cached_pipeline.rswraps aPipelineand
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 andclear_cache()is required
before transforming one. Up to
max_cache_entriesinputs are remembered (16 by default) with FIFO eviction;
0disables caching entirely.cache_size()reports the current count, a
re-fit clears the cache, and the wrapper's output always matches the wrapped
Pipeline::transformfor the input it was computed from (#75). -
ConditionalPipelineinsrc/pipeline/conditional_pipeline.rsroutes 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 optionalfallback
transformer or are dropped. Each transformer receives only its own columns. -
DataQualityReportinsrc/automation/data_quality_report.rssummarises a
frame before modelling: per-column nulls,NaNand±Infcounts, unique
counts and cardinality buckets,Float64moments
(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 emitsRecommendations (drop, impute,
scale, encode, remove duplicates) soAutoPipelinecan consume the same
heuristics. Diagnostic, not a transformer: no fitted state, the input frame is
never modified.print_summaryandto_markdownrender the report;to_json
waits on the optionalserdefeature (issue #28). -
SchemaValidatorfoundation insrc/traits/schema.rs: a transformer can now
describe the input it needs withSchemaSpec/ColumnRequirement
(Named,Dtype { min_count },NameOnly) via the newRequiresSchema
trait, andvalidate_schema(&spec, &df)reports every unmet requirement in one
InvalidInputerror (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 insidetransform.StandardScaler,
MinMaxScaler,RobustScaler,Binarizer,OneHotEncoderand
VarianceThresholdimplementRequiresSchema(#82). -
AutoScalerinsrc/preprocessing/auto_scaler.rspicks a scaling strategy
perFloat64column from the column's own statistics instead of making the
caller choose betweenStandardScaler,MinMaxScaler,RobustScaler,
MaxAbsScalerandPowerTransformer.fitinspects each column and
delegates to aColumnTransformerthat 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; otherwiseStandardScaler.ScalingStrategy::Autois the
default andstrategy(...)forces a single scaler for every column;
chosen_name()andcolumn_types()expose the selection (#86). -
AutoImputerinsrc/preprocessing/auto_imputer.rspicks an imputation
strategy perFloat64column from the column's missing-value pattern and
distribution instead of making the caller choose betweenMean,Median,
MostFrequentandConstant.fitskips columns with no missing value,
followsNullColumnBehaviorfor an entirely null column (Dropby default,
plusErrorandFill), leaves a column at or above
high_null_threshold(default0.5) unchanged, and otherwise picks
Medianwhen|skewness| > skew_threshold(default1.0) andMean
otherwise. Delegation runs through aColumnTransformerwith one
SimpleImputerper strategy subset, so a frame mixing a near-Gaussian
column, a skewed one and aStringcolumn is handled in a single pass;
force_strategy(...)replaces the heuristic, andchosen_name()and
column_types()expose the selection (#87).
Fixed
FeatureUnion::fitnow rejects a DataFrame with 0 columns with
Error::InvalidInput, matchingColumnTransformerand
ConditionalPipeline, instead of fitting and failing later attransform
with "produced no output columns" (#253).RollingAggregator::fitandDifference::fitnow reject configured columns
that are notFloat64withError::InvalidInput, instead of reporting the
transformer fitted and failing later attransform. Frames that previously
fit with aStringor integer configured column now hard-error; cast those
columns before fitting (#221).PolynomialFeatures.transformnow 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 withError::InvalidInput(atfit, and attransformfor a
column that only appears then) (#207).MissingIndicatornow rejects generated indicator column names that collide
with existing input columns or other planned indicator columns, returning
Error::InvalidInputatfitandtransforminstead of silently
overwriting user columns with Polars'with_column(#196).AutoTypeDetector::transformnow 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,columnsandcheck_positivenow clear the fitted
state when called afterfit, so the transformer must be refit, matching
PowerTransformer's builders. Previouslymethodkept the fit: fitting
Log1pon[0, 1, 2]and then switching toLntransformed to
[-inf, 0, 0.693]without an error, andinverse_transformused the new
method too.transformandinverse_transformnow returnError::NotFitted
until the refit, which re-runs the domain check for the new method (#208).KBinsDiscretizer.fit(one-hot modes) andPolynomialFeatures.fitnow
reject generated output names that collide, returningError::InvalidInput
instead of fitting and then failing everytransformwith a duplicate-column
error. ForKBinsDiscretizerthat is a{column}_bin_{j}name equal to a
column passed through unchanged; forPolynomialFeaturesit is two terms
with the same name, such as an input columna_b_internext to thea * b
interaction. Because term names do not encode exponents,PolynomialFeatures
withdegree >= 3andinteraction_only(false)always produces such a
collision (a^2anda^3are both nameda^) and now fails atfit
instead of attransform(#209).Binarizernow rejects input frames with noFloat64column at both fit
and transform time using the sharedrequire_f64_columnscheck, 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-Float64columns accompanying at least oneFloat64
column keep their pass-through behaviour (#182). Frames that previously fit
and transformed successfully because they held noFloat64column at all
now hard-error; cast them before fitting.QuantileTransformerno longer treats a column with genuine but tiny spread
as constant. The degeneracy guard used an absolutef64::EPSILONthreshold,
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-value0.5and 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 documented0.5(#180).StringCleaner.fitnow validates each replacement template against the
pattern it runs on and returnsError::InvalidInputnaming the bad
template, instead of passing it through totransform, where theregex
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")—$1on a pattern without capture groups — or
a${name}reference to an undefined group is now rejected atfit.
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).