Skip to content

fix(splines): choose thin-plate landmarks from complete rows - #152

Merged
mkumar73 merged 2 commits into
mainfrom
fix/151-thin-plate-missing-rows
Nov 30, 2026
Merged

mkumar73 merged 2 commits into
mainfrom
fix/151-thin-plate-missing-rows

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #151.

ThinPlateSplineTransformer declares allow_nan=True, and its transform turns a missing coordinate into a NaN row, but fit failed on any training row with NaN. A tprs feature group with missing_policy="propagate" therefore could not be fitted on data with gaps, although docs/core_concepts/missing_values.md says splines propagate missing values.

Root cause

fit passed every validated row, NaN rows included, to _select_landmarks. KMeans rejects NaN, and with landmark_strategy="subsample" a NaN row could become a landmark, which made the SVD of the projection fail. The landmarks define the whole basis, so they must be complete.

Fix

ThinPlateSplineTransformer.fit (pretab/expansion/spline/multivariate/thin_plate.py) selects the landmarks from the rows without a missing value. The minimum-sample check (n_components + n_features + 1) counts those rows; when some rows are incomplete, the error says how many. Without missing values, X is passed unchanged, so the landmarks, the random draws and the basis are identical to main.

transform is unchanged: a row with a missing coordinate is NaN in every basis column, and a leading bias column stays 1.

Behaviour changes

  • fit succeeds on data with missing values, with either landmark strategy. Before, it raised ValueError (k-means) or LinAlgError (subsample).
  • A tprs feature group with missing_policy="propagate" fits and returns NaN rows for incomplete rows, like tensorspline.
  • If too few complete rows remain, InsufficientSamplesError reads e.g. needs at least 8 samples without a missing value (3 of 10 rows have one); got 7. Without missing values, the message is unchanged.

Documentation

  • ThinPlateSplineTransformer docstring, Notes: how missing values are handled at fit and transform.
  • New NumPy-style docstrings for fit (with Raises) and transform, which had none.
  • docs/core_concepts/missing_values.md already promises NaN propagation for splines, so the docs now match the behaviour without edits. README, homepage, tutorials and docs/representations/spline_expansions.md say nothing contrary.

Tests

  • tests/expansion/spline/test_thinplate_transformer.py:
    • test_tprs_fits_on_rows_with_missing_values (k-means and subsample; 1, 2 and 3 features): finite landmarks, identical to a fit on the complete rows; NaN rows for incomplete rows. Fails on main, passes here.
    • test_tprs_missing_rows_keep_the_bias_column: fails on main, passes here.
    • test_tprs_counts_only_complete_rows_towards_the_minimum_sample_size: fails on main, passes here.
  • tests/integration/test_feature_groups.py::test_propagated_missing_value_gives_a_nan_group_row (tensorspline, tprs): the tprs case fails on main and passes here; tensorspline is a guard that passes on both.

Reproduction

The script from #151 on this branch:

allow_nan tag: True
kmeans -> fitted
subsample -> fitted
Preprocessor(missing_policy='propagate') -> fitted; NaN rows: 23

23 is the number of rows with a missing value.

Checks

  • just test: 4686 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): 4503 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.expansion.spline.multivariate; no import direction changes.

Merge notes

ThinPlateSplineTransformer declares allow_nan and its transform turns a
missing coordinate into a NaN row, but fit passed rows with NaN to the
landmark selection: k-means rejected them, and a subsampled NaN landmark
made the SVD fail. A tprs feature group with missing_policy="propagate"
could therefore not be fitted.

fit now selects the landmarks from the rows without a missing value and
counts only those rows towards the minimum sample size. Without missing
values the landmarks and the basis are unchanged. Add the missing fit and
transform docstrings.

Fixes #151
@mkumar73 mkumar73 self-assigned this Nov 29, 2026
@mkumar73
mkumar73 merged commit 763f648 into main Nov 30, 2026
19 checks passed
@mkumar73
mkumar73 deleted the fix/151-thin-plate-missing-rows branch November 30, 2026 05:51
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.

ThinPlateSplineTransformer declares allow_nan but fit crashes on any training row with a missing value

2 participants