Skip to content

fix(configs): re-resolve PreprocessingConfig after field changes - #490

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/preprocessing-set-params
Open

ChrisW09 wants to merge 1 commit into
mainfrom
fix/preprocessing-set-params

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #489

Problem

Changing a PreprocessingConfig after construction had no effect on the preprocessor for most fields. Two kinds of change were affected:

  • set_params(), including the preprocessing_config__* keys that scikit-learn searches set on the estimator.
  • Direct attribute assignment.

get_params() reported the new values, but fitting used the old ones. A GridSearchCV over preprocessing_config__numerical_method therefore trained every candidate with the base preprocessing: candidates scored identically, and best_estimator_ disagreed with best_params_.

Root cause

PreprocessingConfig.__post_init__ resolves canonical and legacy fields once into private _resolved_* attributes, and to_preprocessor_kwargs() reads only that cache. BaseEstimator.set_params() and attribute assignment never re-run __post_init__.

Fix

__post_init__ now records the field values the cache was resolved from. to_preprocessor_kwargs() re-runs validation and resolution whenever those values have changed. Every consumer goes through to_preprocessor_kwargs(), so the fix lives in one place:

  • SklearnBase.__init__ / set_params
  • _FitMixin._build_model
  • SklearnBaseLSS.build_model
  • build_preprocessor

Invalid values set after construction are now rejected with the same validation errors the constructor raises, instead of being ignored. Configs that are not changed after construction behave exactly as before.

Tests

  • tests/configs/test_config_contracts.py:
    • set_params and attribute assignment are reflected in to_preprocessor_kwargs();
    • an invalid value set after construction raises InvalidParamError when it is used.
  • tests/models/test_estimator_configuration.py:
    • set_params(preprocessing_config__numerical_method=..., preprocessing_config__output_dim=...) reaches _preprocessor_kwargs and the fitted feature metadata;
    • a direct preprocessing_config.output_dim = 3 assignment changes the fitted width.

All 5 new tests fail on main and pass with this change.

Docs

to_preprocessor_kwargs() documents that fields changed after construction are validated and resolved again. No user-facing page needed a change: the documented GridSearchCV example now works as described.

Checks

  • just test: 3241 passed, 46 skipped, 28 xfailed; coverage 91.31%
  • just docs: build succeeded (warnings treated as errors)
  • just check: all hooks passed (ruff, prettier, pyright)

PreprocessingConfig resolved its canonical and legacy fields once in
__post_init__ and to_preprocessor_kwargs() only read that cache, so
values changed through set_params() (including the
preprocessing_config__* keys a GridSearchCV sets) or by attribute
assignment never reached the preprocessor while get_params() reported
them. to_preprocessor_kwargs() now validates and resolves the fields
again whenever they changed since the last resolution.

Fixes #489

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] PreprocessingConfig changes made via set_params() or attribute assignment are ignored, so searches over preprocessing_config__* tune nothing

1 participant