Skip to content

Add Pipeline with nested get_params / set_params - #13

Merged
akifkulll merged 1 commit into
mainfrom
feat/pipeline
Oct 31, 2026
Merged

akifkulll merged 1 commit into
mainfrom
feat/pipeline

Conversation

@akifkulll

Copy link
Copy Markdown
Collaborator

Closes #5

Summary

Adds Pipeline, a BasePreprocessor that runs blocks in order and feeds each block's output into the next.

  • Steps are blocks or (name, block) pairs. Unnamed blocks are named after their lowercase class name; repeated class names get -1, -2 suffixes.
  • fit_transform runs the chain once and reuses each step's output (instead of fit().transform(), which would run every step twice and would be wrong for blocks whose fit_transform differs, such as a future cross-fitted target encoder).
  • Nested get_params / set_params (<name>__<param>), step replacement by name, named_steps, and get_feature_names_out chained through every step.
  • Step blocks are fitted in place, as in scikit-learn.

Design decisions beyond the issue text:

  • Step names are validated wherever they are needed (fit, get_params, set_params, named_steps), not only in fit: GridSearchCV calls get_params before fitting, and duplicate names would otherwise silently merge two steps' parameters. __init__ still does no validation.
  • "steps" is reserved as a step name (it would collide with the steps parameter in get_params).
  • An explicit name that collides with an automatic one raises ValueError instead of renumbering, so adding a step never changes another step's address.
  • A replaced unnamed step is stored as (name, block), so its name and every <name>__<param> address stay the same. The user's list is never modified.
  • set_params validates the whole call first, recursively through nested pipelines; an invalid call changes nothing.
  • An empty pipeline raises ValueError.

How was it tested

  • tests/test_pipeline.py: 37 tests with small test blocks defined in the file (one renames columns, to cover get_feature_names_out chaining).
  • ruff format --check ., ruff check . and pytest pass on all three CI configurations: Python 3.10 + scikit-learn 1.7.2 (106 passed), Python 3.13 + scikit-learn 1.9.1 (106 passed), Python 3.10 + scikit-learn 1.3.2 (105 passed, 1 skipped: tags API). Also 106 passed locally on Windows, Python 3.12.
  • Manual check with the real blocks: Pipeline([("imputer", MissingValueImputer()), FeatureScaler()]) inside make_pipeline(..., SVR()) and GridSearchCV over pipeline__imputer__strategy and pipeline__featurescaler__method.

Checklist

  • ruff format . and ruff check . pass
  • pytest passes
  • New or changed blocks follow the block rules in CONTRIBUTING.md
  • Tests include a leakage test (statistics come from the training data only) and a run inside sklearn cross_val_score

@akifkulll akifkulll self-assigned this Oct 31, 2026
@akifkulll akifkulll added the core Core framework: base class, pipeline label Oct 31, 2026
@akifkulll
akifkulll requested a review from ata-sesli October 31, 2026 15:02
@akifkulll
akifkulll merged commit 98a285e into main Oct 31, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core framework: base class, pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Pipeline with nested get_params / set_params

2 participants