fix(binning): make get_feature_names_out follow the sklearn contract - #42
Open
ChrisW09 wants to merge 1 commit into
Open
fix(binning): make get_feature_names_out follow the sklearn contract#42ChrisW09 wants to merge 1 commit into
ChrisW09 wants to merge 1 commit into
Conversation
``CustomBinTransformer.get_feature_names_out()`` raised without arguments and
returned a plain list with them, so it broke ``Pipeline.get_feature_names_out()``
for any pipeline containing it:
t.get_feature_names_out() -> InvalidParamError: input_features must be specified
Pipeline([...]).get_feature_names_out() -> same
Generate ``x0, x1, ...`` when ``input_features`` is None, return an ndarray, and
guard on being fitted -- matching ``NoTransformer``, ``ToFloatTransformer`` and
``ContinuousOrdinalTransformer``, which already had this treatment (see the
docstring of tests/test_feature_names_out.py).
Two existing tests pinned the old behaviour and are updated:
``test_custom_bin_transformer_feature_names_out`` compared against a list, and
``..._out_raises`` asserted the no-argument call raises. The latter becomes a
``NotFittedError`` check for the un-fitted call, which is the guard that should
actually be there.
Closes #36
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ChrisW09
force-pushed
the
fix/custombin-feature-names-contract
branch
from
July 27, 2026 20:50
4d2b9ee to
07e56cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #36.
Problem
CustomBinTransformer.get_feature_names_out()raised when called with no arguments andreturned a plain
listwhen given them. Both break scikit-learn's contract, and the firstbreaks
Pipeline.get_feature_names_out()for any pipeline containing the transformer:The package had already fixed exactly this for three sibling transformers — the docstring of
tests/test_feature_names_out.pyrecords it as "get_feature_names_out(None)defaults togenerated
x0, x1, ...names instead of raising, forNoTransformer,ToFloatTransformerand
ContinuousOrdinalTransformer" — butCustomBinTransformerwas missed.Fix
Mirror
NoTransformer.get_feature_names_out: generatex0, x1, ...wheninput_featuresisNone, always return an ndarray, and guard on being fitted (which the old version did not doat all).
Changed existing expectations
Both flagged in the issue:
test_custom_bin_transformer_feature_names_outassertednames == ["feature1"], whichonly holds for a list. Now checks the ndarray type and its contents.
test_custom_bin_transformer_feature_names_out_raisesasserted the no-argument callraises — i.e. it pinned the defect. Replaced with
test_custom_bin_transformer_feature_names_out_before_fit_raises, checking theNotFittedErrorthat the newcheck_is_fittedguard produces, which is the assertion thatshould have been there.
Tests
Three added beyond those: generated default names, the pipeline call, and
len(get_feature_names_out()) == transform(X).shape[1].Full suite: 483 passed, 9 xfailed.
ruff check pretabclean apart from the pre-existingRUF100; the remainingI001/B017/RUF043in this test file all predate the change.pyright unchanged at 71.
🤖 Generated with Claude Code