Repository navigation
fix(config): inherit NumPy scalar settings as Python values - #158
Merged
Merged
Conversation
A structured feature_preprocessing entry or feature group fills its omitted fields from the Preprocessor settings. Those were copied into the RepresentationConfig unchanged, and its builtin-only checks rejected NumPy scalars such as np.int64 output_dim / random_state / degree or np.bool_ adaptive / target_aware. Any fit with an override therefore failed for settings drawn from a NumPy GridSearchCV grid, which PreTab 1.0.0 accepted. _resolve_representation now converts inherited NumPy scalars with .item() before building the resolved config. Explicit RepresentationConfig fields keep their strict JSON-compatible contract. Fixes #157
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 #157.
A
Preprocessorwith NumPy scalar settings (output_dim=np.int64(5),random_state=np.int64(3),degree=np.int64(2),adaptive=np.True_,target_aware=np.False_, ...) failed atfitand inget_resolved_config()as soon as afeature_preprocessingoverride or a feature group inherited them. This brokeGridSearchCVgrids built with NumPy for any 1.1 per-feature configuration. PreTab 1.0.0 accepted these settings.Root cause
PreprocessorConfig._resolve_representation(pretab/compose/config.py) fills a structured entry's omitted common fields and familyparamsfrom the constructor settings. It copied them unchanged intoreplace(requested, ...), and the JSON-compatibleRepresentationConfigchecks (type(value) is int/bool, and_freeze_config_valueforparams) rejected NumPy scalars.Fix
A new helper
_builtin_settingreturnsvalue.item()for a NumPy scalar (np.generic) and leaves other values unchanged._resolve_representationapplies it to the inherited common fields (output_dim,target_aware,placement_strategy,adaptive, the adaptive bounds) and to the sharedparams(degree,task,random_state). Values the user writes into aRepresentationConfig(or its mapping form) are not converted; their strict JSON contract is unchanged.Behaviour changes
InvalidParamErrornow succeed. Their output,get_resolved_config(), spec and fingerprint equal those of the same configuration with Python values.Documentation
docs/core_concepts/configuration.md(per-field inheritance): constructor settings may be NumPy scalars, such as the values of aGridSearchCVgrid built withnp.arange, and an entry inherits them as the equal Python values.RepresentationConfigdocstring (finite JSON-compatible values only) stays accurate, since the conversion happens before the inherited values are stored.Tests
In
tests/compose/test_representation_config.py:test_numpy_scalar_settings_are_inherited_by_overrides: five NumPy settings × three override forms ("rbf","bspline", aRepresentationConfig). Each compares output, resolved config and a strict-JSON spec with the Python-valued fit. 13 of the 15 cases fail onmainand all pass here. The two exceptions aredegreewith an RBF override, which does not inheritdegree, so they are guards.test_numpy_scalar_settings_are_inherited_by_feature_groups: a tensor-product group withdegreeandrandom_stateas NumPy integers. Fails onmain, passes here.test_grid_search_over_numpy_output_dims_with_an_override:GridSearchCVovernp.arangewidths with a B-spline override. Fails onmain, passes here.Reproduction
The script from #157 on this branch:
The group and
GridSearchCVcases print nothing because they no longer raise.Checks
just test: 4693 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.config, which now imports NumPy (already a core dependency); no import direction changes.Merge notes
main. Git merges this branch cleanly with fix(binning): reject edges the soft encoding cannot use #150, fix(splines): choose thin-plate landmarks from complete rows #152, fix(preprocessor): accept NumPy scalars for cat_cutoff #154 and fix(preprocessor): re-infer object array columns at fit #156.cat_cutoff, which happens in column-type detection rather than in this resolver.