Repository navigation
fix(preprocessor): accept NumPy scalars for cat_cutoff - #154
Merged
Merged
Conversation
detect_column_types checked cat_cutoff with isinstance(..., float) and isinstance(..., int), so np.int64 (as produced by np.arange in a GridSearchCV grid) and np.float32 raised InvalidParamError, while True was silently read as the count 1. The check also ran only inside the column loop. cat_cutoff is now validated once, before the loop: any numbers.Integral is a unique-count cutoff, any other numbers.Real a unique-ratio cutoff, and bool / np.bool_ are rejected. Fixes #153
This was referenced Nov 29, 2026
mkumar73
approved these changes
Nov 30, 2026
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 #153.
Preprocessor(cat_cutoff=...)rejected NumPy scalars, so aGridSearchCVgrid such as{"preprocessor__cat_cutoff": np.arange(4, 12, 4)}failed on its first candidate. A boolean was silently accepted as the count1.Root cause
detect_column_types(pretab/compose/feature_detection.py) branched onisinstance(cat_cutoff, float)andisinstance(cat_cutoff, int).np.int64andnp.float32are neither, andboolis anint. The check ran inside the per-column loop, so it was reached only when the frame had a column to classify.Fix
cat_cutoffis validated once, before the column loop:numbers.Integral(Python or NumPy integer) is an absolute unique-count cutoff;numbers.Real(Python or NumPy float) is a unique-ratio cutoff;bool/np.bool_and non-numbers raise the sameInvalidParamErroras before.The value is converted to a Python
intorfloatbefore the comparisons. Python ints and floats classify exactly as before.Behaviour changes
output_dimand the other integer parameters.cat_cutoff=True/Falsenow raisesInvalidParamErrorinstead of acting as the count1/0.cat_cutoffis reported even when the frame has no integer column.Documentation
Preprocessordocstring,cat_cutoff: NumPy scalars are read the same way; a boolean is rejected.detect_column_typesdocstring: the same, plus aRaisesentry forInvalidParamError.docs/and the tutorials use plain Python values and need no change.Tests
tests/compose/test_feature_detection.py::test_numpy_scalar_cutoffs_follow_their_python_counterparts(np.int64,np.int32,np.uint8,np.float32,np.float16): fails onmain, passes here.tests/compose/test_feature_detection.py::test_non_numeric_cat_cutoff_raises_even_without_integer_columns: theTruecase fails onmainand passes here;np.bool_(False)andNoneare guards that pass on both.tests/integration/test_preprocessor.py::test_grid_search_accepts_numpy_cat_cutoff_values: aGridSearchCVovernp.arangecutoffs, plus the expected classification at both cutoffs. Fails onmain, passes here.Reproduction
The script from #153 on this branch:
to_spec()/from_spec()round-trip a NumPy cutoff (it is restored as the equal Python number) with identical transform output.Checks
just test: 4685 passed, 59 skipped, 7 xfailed; coverage 95.71% (gate 90%).scripts/quickstart.pypasses.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).pretab.compose.feature_detection(plus the facade docstring); no import direction changes.Merge notes
main. Independent of fix(binning): reject edges the soft encoding cannot use #150 and fix(splines): choose thin-plate landmarks from complete rows #152.