Skip to content

fix(registry): honour preprocessor_compatible for categorical methods - #180

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/179-categorical-preprocessor-compatible
Open

ChrisW09 wants to merge 1 commit into
mainfrom
fix/179-categorical-preprocessor-compatible

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #179.

A categorical method registered with preprocessor_compatible=False was still fitted by Preprocessor(categorical_method=...). The same method in feature_preprocessing was rejected, and numerical methods with the flag were excluded, so the selection paths disagreed.

Root cause

register_spec (pretab/compose/registry.py) added every categorical spec to CATEGORICAL_METHODS, the whitelist that categorical_method= resolves against. The initial whitelist was built the same way. NUMERICAL_METHODS filters on spec.preprocessor_compatible.

Fix

  • The initial CATEGORICAL_METHODS holds only categorical specs with preprocessor_compatible=True.
  • register_spec adds a categorical spec to it only when the spec is preprocessor compatible. It still discards the name first, so an override=True re-registration as standalone removes it.
  • The method stays in TRANSFORMER_REGISTRY and in list_representations, as numerical standalone methods do.
  • All built-in categorical methods are preprocessor compatible, so the built-in whitelist is unchanged.

Behaviour changes

  • Preprocessor(categorical_method=<standalone method>) now raises InvalidParamError, like the numerical case and the feature_preprocessing path. Before, it fitted the method per column.
  • Nothing else changes for built-in or preprocessor-compatible registered methods.

Documentation

  • register_representation docstring (preprocessor_compatible): it covers numerical_method / categorical_method and feature_preprocessing, for numerical and categorical methods alike, and the method stays registered and listed.
  • register_spec docstring and the comment on CATEGORICAL_METHODS.
  • The extension API page and the custom-representation tutorial do not discuss this flag for categorical methods.

Tests

In tests/extension/test_registration_discovery.py, which restores the registry after each test:

  • test_standalone_categorical_method_is_not_selectable_through_preprocessor (categorical_method and feature_preprocessing): the method is registered and listed but not whitelisted, and both selections raise. Fails on main, passes here.
  • test_overriding_a_categorical_method_as_standalone_removes_it_from_the_whitelist: fails on main, passes here.
  • test_builtin_categorical_whitelist_holds_only_preprocessor_compatible_methods: guard that passes on both.

Reproduction

The script from #179 on this branch:

in NUMERICAL_METHODS: False | in CATEGORICAL_METHODS: False
numerical_method='standalone_num'                -> InvalidParamError
categorical_method='standalone_cat'              -> InvalidParamError
feature_preprocessing={'city': 'standalone_cat'} -> InvalidParamError

Checks

  • just test: 4680 passed, 59 skipped, 7 xfailed; coverage 95.71% (gate 90%).
  • Minimum dependencies (CI job: Python 3.11, numpy 1.24.4, pandas 2.0.3, scipy 1.10.1, scikit-learn 1.6.0): 4497 passed, 173 skipped, 7 xfailed; scripts/quickstart.py passes.
  • just docs: strict build succeeds.
  • just check: all pre-commit and pre-push hooks pass (file hygiene, ruff format, ruff lint, prettier, pyright with 0 errors).
  • The change stays inside the registry (plus the extension docstring); no import direction changes.

Merge notes

register_spec added every categorical spec to CATEGORICAL_METHODS, so a
categorical method registered with preprocessor_compatible=False was
still fitted by Preprocessor(categorical_method=...), although the same
method in feature_preprocessing was rejected and numerical methods with
the flag were excluded from NUMERICAL_METHODS.

CATEGORICAL_METHODS is now built from, and extended with, only the
categorical specs that are preprocessor compatible. The method stays
registered and listed.

Fixes #179

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.

register_representation(preprocessor_compatible=False) is ignored for categorical methods selected via categorical_method

1 participant