scikit-lego
The scikit-lego pack has 23 rules, and xpd can fix 5 of them.
The scikit-lego rules report arguments that give a wrong number without an error, steps that read
the wrong rows or can't be fitted, and code that raises or warns on scikit-lego 0.9.10, in each
file that imports sklego. Every number about the scikit-lego rules was measured on scikit-lego 0.9.10 with
scikit-learn 1.9.1, NumPy 2.5.5 and pandas 3.1.1. The examples assume that the names they use are
imported, and names such as X_train, y_test and model stand for values from your program.
A rule document whose advice needs a newer release of scikit-lego carries since. xpd reads the
installed version from the project's venv and skips the document on an older release. When the
venv has no scikit-lego, or there is no venv, every document runs.
The pack has no package checks. cvxpy, umap-learn and formulaic are extras that only some estimators need, and a package check can't see which estimators a project uses. When an extra is missing, scikit-lego raises an ImportError that names it.
The proof each rule needs
Section titled “The proof each rule needs”A rule is an error only when code was run that shows the wrong number or the exception, and
its message quotes what was measured. A proof is one of the following kinds:
| Proof | What runs |
|---|---|
| number | The old and the new form on the same data, and a comparison of what they return. |
| interpreter | The old form, with its exception or its warning under python -W error, and the new form, which runs clean. |
| speed | The old form, timed at two settings. |
A rule is a warning when the proof passed and a pattern can't see whether the code wants the old
form. A rule is info when no proof of the listed kinds applies.
The rules were then run over scikit-lego's own source, docs scripts and tests at the 0.9.10 tag, 134 Python files, and every report was read. Of the 46 reports there, 42 are on a form that the rule describes, most of them in tests that build a deprecated or superseded class or check that a wrong call raises. The other 4 are on code that is right as it stands:
- the package's own export of
PandasTypeSelector - two tests of
add_lagswith a positive lag - one test that passes
threshold=0.1toGMMOutlierDetectoronly to build an object
After that reading, debug-pipeline-default-log was narrowed to leave a file alone when it
imports logging or uses pytest's caplog, which removed 5 reports. unseeded-random-estimator
was narrowed to leave test files alone, which removed 7.
| Rule | Severity | Proof | Reports on scikit-lego's files | On code that is right | Fix |
|---|---|---|---|---|---|
thresholder-score |
error | number: 0.887 at three thresholds against 0.740, 0.887 and 0.847 | 0 | 0 | none |
estimator-transformer-proba |
error | number: shape (800, 1) for 400 rows | 0 | 0 | none |
column-capper-fraction |
error | number: 9,910 of 10,000 values changed against 1,000 | 0 | 0 | none |
dict-mapper-not-int |
error | number: 0.5 and 1.7 became 0 and 1. Interpreter: ValueError | 0 | 0 | none |
regression-outlier-column-name |
error | number: coefficients 0, 0 and 1, and 11 rows flagged against 10 | 2 | 0 | none |
pca-outlier-after-scaler |
error | number: 320 rows flagged against 20 | 0 | 0 | none |
outlier-threshold |
error | interpreter: ValueError. Number: 380 of 400 rows flagged against 20 | 1 | 1 | none |
grouped-shrinkage-arguments |
error | number: probabilities bit equal with and without the keyword. Interpreter: TypeError | 0 | 0 | unsafe |
add-lags-positive |
warning | number: accuracy 0.996 against 0.474 on noise | 2 | 2 | none |
decay-on-shuffled-rows |
warning | number: slope 1.621 against 3.028 | 0 | 0 | none |
outlier-remover-before-model |
error | interpreter: ValueError | 0 | 0 | none |
decay-without-sample-weight |
error | interpreter: ValueError, TypeError | 0 | 0 | none |
zero-inflated-roles |
error | interpreter: ValueError | 2 | 0 | none |
scorer-called-as-metric |
error | interpreter: IndexError, TypeError. Number: a function where a score is expected | 0 | 0 | unsafe |
dataset-frame-and-xy |
error | interpreter: ValueError | 0 | 0 | none |
log-step-extra-bare |
error | number: a function where a frame is expected. Interpreter: ValueError | 1 | 0 | none |
selector-without-feature-names |
error | interpreter: ValueError, AttributeError | 0 | 0 | none |
debug-pipeline-default-log |
info | number: 0 characters printed | 0 | 0 | none |
removed-in-sklego |
error | interpreter: ImportError, ModuleNotFoundError, TypeError | 0 | 0 | unsafe |
deprecated-in-sklego |
warning | interpreter: DeprecationWarning | 10 | 1 | safe |
superseded-estimator |
warning, info | interpreter: UserWarning | 28 | 0 | none |
group-time-series-split-folds |
warning | speed: 1.08 s at 5 folds against 10.48 s at 6 | 0 | 0 | none |
unseeded-random-estimator |
info | none of the three | 0 | 0 | none |
A rule with no report on scikit-lego's files was checked only on the pack's sample files, so its rate of wrong reports on real code is not measured. The pack was not judged on held-back files from other projects, and it has no recall number.
Arguments that give a wrong number
Section titled “Arguments that give a wrong number”Each rule in the group reports an argument that gives another number than the code asks for, without an error, or that raises where the argument is read.
| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| thresholder-score | error | none | Thresholder.score ignores the threshold, so a search over thresholds scores every one the same. |
| estimator-transformer-proba | error | none | EstimatorTransformer reshapes its output to one column, so predict_proba comes back with twice as many rows and a pipeline around it raises. |
| column-capper-fraction | error | none | ColumnCapper reads quantile_range in percent, so (0.05, 0.95) caps almost every value at a percentile below 1. |
| dict-mapper-not-int | error | none | DictMapper casts every mapped value to int, so a float loses its fraction without a warning. |
| regression-outlier-column-name | error | none | RegressionOutlierDetector with a column name keeps the target among the features, so the inner model predicts the target from itself. |
| pca-outlier-after-scaler | error | none | After a centring step such as StandardScaler, the default relative error of PCAOutlierDetection divides by numbers near zero and flags many normal rows. |
| outlier-threshold | error | none | These outlier detectors need a valid threshold, and fit raises ValueError without one or with one out of range. |
| grouped-shrinkage-arguments | error | unsafe | GroupedClassifier drops a shrinkage keyword without an error, so the setting has no effect. |
Rows and fits
Section titled “Rows and fits”Each rule in the group reports a step fitted on rows it shouldn't see in that order, or a meta estimator built around a model it can't fit.
| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| add-lags-positive | warning | none | add_lags with a positive lag copies the value of a later row, so lag 1 is the next row and leaks the future into the features. |
| decay-on-shuffled-rows | warning | none | DecayEstimator gives the last rows the most weight, and train_test_split shuffles the rows, so the weights no longer follow time. |
| outlier-remover-before-model | error | none | OutlierRemover drops rows of X and leaves y whole, so the model after it raises ValueError. |
| decay-without-sample-weight | error | none | DecayEstimator passes sample_weight to the fit of the model it wraps, so wrapping a Pipeline or a model without sample_weight raises ValueError. |
| zero-inflated-roles | error | none | ZeroInflatedRegressor takes the classifier first and the regressor second, so swapping them raises ValueError at fit. |
Scorers, datasets and helpers
Section titled “Scorers, datasets and helpers”Call each scikit-lego scorer, dataset loader and pipeline helper with the arguments it reads, because the forms below raise or return something other than the code expects.
| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| scorer-called-as-metric | error | unsafe | These fairness functions return a scorer that takes an estimator, so wrapping them in make_scorer or calling them on labels raises and makes every score NaN. |
| dataset-frame-and-xy | error | none | With as_frame=True, the scikit-lego loaders ignore return_X_y=True and return one frame with the target in it, so unpacking into X and y raises ValueError. |
| log-step-extra-bare | error | none | A bare @log_step_extra takes the decorated function as a log function, so calling the function returns another function and not a frame. |
| selector-without-feature-names | error | none | ColumnSelector, ColumnDropper and TypeSelector have no set_output and no get_feature_names_out, so calling either on a pipeline that holds them raises. |
| debug-pipeline-default-log | info | none | log_callback="default" logs at level INFO, which Python hides until logging is set up, so the pipeline prints nothing. |
Removed, deprecated and superseded forms
Section titled “Removed, deprecated and superseded forms”Each rule in the group reports a form that raises or warns on scikit-lego 0.9.10, and each removed
form raised when it was run. The deprecated and superseded forms were run under python -W error,
where the old form raised its warning and the new form ran clean. The messages take each
replacement from the text of the warning or from the release that made the change. A fix of a
removed form turns code that raises into code that runs, so no such fix is safe.
| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| removed-in-sklego | error | unsafe | These forms were removed from scikit-lego, so the import or the call raises. |
| deprecated-in-sklego | warning | safe | These names, keywords and attributes warn on scikit-lego and will be removed. |
| superseded-estimator | warning | unsafe | scikit-lego warns on these classes and asks you to use a replacement, such as scikit-learn's QuantileRegressor. |
Speed and repeatable runs
Section titled “Speed and repeatable runs”Keep GroupTimeSeriesSplit to few folds, and give each estimator that draws random numbers a seed, so a run finishes and repeats.
| Rule | Severity | Fix | What it finds |
|---|---|---|---|
| group-time-series-split-folds | warning | none | GroupTimeSeriesSplit tries every combination of split points, so each extra fold multiplies the time, from about 1 second at 5 folds to 10 at 6. |
| unseeded-random-estimator | info | none | RandomRegressor and RandomAdder without random_state draw new numbers on every call, so results change between calls. |
Habits the pack does not report
Section titled “Habits the pack does not report”The pack has no rule for the following habits:
MaximumRelevanceMinimumRedundancywith the defaultkind="auto"scores a whole-number regression target as classes. On one such target it picked the features 0, 1 and 3, against 0, 1 and 4 withkind="regression". A pattern can't see the target, and a rule on every call withoutkindwould report the library's own tests.RegressionOutlierDetectorwith a column position on a frame, andTimeGapSplit,RandomAdderandOutlierRemovergiven an input type they don't take, depend on whatfitis given, which a pattern can't see.- The extras cvxpy, umap-learn and formulaic have no rule, because a package check can't see which estimators a project uses.