Skip to content

fix(config): inherit NumPy scalar settings as Python values - #158

Merged
mkumar73 merged 1 commit into
mainfrom
fix/157-numpy-inherited-settings
Nov 30, 2026
Merged

mkumar73 merged 1 commit into
mainfrom
fix/157-numpy-inherited-settings

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #157.

A Preprocessor with 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 at fit and in get_resolved_config() as soon as a feature_preprocessing override or a feature group inherited them. This broke GridSearchCV grids 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 family params from the constructor settings. It copied them unchanged into replace(requested, ...), and the JSON-compatible RepresentationConfig checks (type(value) is int / bool, and _freeze_config_value for params) rejected NumPy scalars.

Fix

A new helper _builtin_setting returns value.item() for a NumPy scalar (np.generic) and leaves other values unchanged. _resolve_representation applies it to the inherited common fields (output_dim, target_aware, placement_strategy, adaptive, the adaptive bounds) and to the shared params (degree, task, random_state). Values the user writes into a RepresentationConfig (or its mapping form) are not converted; their strict JSON contract is unchanged.

Behaviour changes

  • Fits that raised InvalidParamError now succeed. Their output, get_resolved_config(), spec and fingerprint equal those of the same configuration with Python values.
  • Configurations with Python settings are unaffected: the helper returns builtins unchanged.

Documentation

  • docs/core_concepts/configuration.md (per-field inheritance): constructor settings may be NumPy scalars, such as the values of a GridSearchCV grid built with np.arange, and an entry inherits them as the equal Python values.
  • The RepresentationConfig docstring (finite JSON-compatible values only) stays accurate, since the conversion happens before the inherited values are stored.
  • README, homepage and tutorials do not mention NumPy-typed settings.

Tests

In tests/compose/test_representation_config.py:

  • test_numpy_scalar_settings_are_inherited_by_overrides: five NumPy settings × three override forms ("rbf", "bspline", a RepresentationConfig). Each compares output, resolved config and a strict-JSON spec with the Python-valued fit. 13 of the 15 cases fail on main and all pass here. The two exceptions are degree with an RBF override, which does not inherit degree, so they are guards.
  • test_numpy_scalar_settings_are_inherited_by_feature_groups: a tensor-product group with degree and random_state as NumPy integers. Fails on main, passes here.
  • test_grid_search_over_numpy_output_dims_with_an_override: GridSearchCV over np.arange widths with a B-spline override. Fails on main, passes here.

Reproduction

The script from #157 on this branch:

output_dim=np.int64(5)     override=None: fitted
output_dim=np.int64(5)     override={'x': 'rbf'}: fitted
random_state=np.int64(3)   override=None: fitted
random_state=np.int64(3)   override={'x': 'rbf'}: fitted
adaptive=np.True_          override=None: fitted
adaptive=np.True_          override={'x': 'rbf'}: fitted

The group and GridSearchCV cases print nothing because they no longer raise.

Checks

  • just test: 4693 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): 4510 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 pretab.compose.config, which now imports NumPy (already a core dependency); no import direction changes.

Merge notes

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
mkumar73 merged commit a9ab1ae into main Nov 30, 2026
19 checks passed
@mkumar73 mkumar73 self-assigned this Nov 30, 2026
@mkumar73
mkumar73 deleted the fix/157-numpy-inherited-settings branch November 30, 2026 07:26
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.

NumPy scalar Preprocessor settings break any fit with a per-feature override or feature group (1.1 regression)

2 participants