Skip to content

fix(splines): reject a feature with a single observed value at fit - #137

Open
xillig wants to merge 1 commit into
OpenTabular:mainfrom
xillig:fix/spline-single-observed-value
Open

xillig wants to merge 1 commit into
OpenTabular:mainfrom
xillig:fix/spline-single-observed-value

Conversation

@xillig

@xillig xillig commented Nov 11, 2026

Copy link
Copy Markdown

Problem

A feature with exactly one observed value (a one-row X, or one non-missing value among NaNs) has no range, like a constant feature, but passed fit: the constant check only ran for two or more observed values.

  • B/M/I splines: fit succeeded, transform failed inside SciPy with ValueError: Need at least two internal knots. (also through Preprocessor(numerical_method="bspline") on a one-row frame).
  • P-spline / tensor-product: all-zero basis rows.
  • Cubic / natural cubic: fewer columns than requested.
import numpy as np
from pretab.transformers import BSplineTransformer
BSplineTransformer().fit(np.array([[2.5]])).transform(np.array([[2.5]]))  # ValueError from SciPy

Fix

Such a feature raises PretabDataError at fit in every spline family that needs spread, as a constant feature does. The message keeps the "1 sample" wording that scikit-learn's check_fit2d_1sample expects, so the conformance tier is unchanged.

Behaviour change: cubic, natural cubic, P-spline and tensor-product now raise where they silently degenerated before. Two distinct values still fit.

Tests and docs

New cases in tests/integration/test_edge_case_contract.py; the edge-case section of choosing_a_method.md and the spline docstrings are updated.

Validation

Checks: full suite (2572 passed, 59 skipped, 7 xfailed, coverage >= 94.79%), ruff format / ruff check, pyright (no new diagnostics), docs build with -W, scripts/quickstart.py. Merges cleanly with main and with #136.

A feature with exactly one observed value (a one-row X, or one non-missing
value among NaNs) has no range, like a constant feature, but slipped past
the constant check, which only ran for two or more observed values.

The B/M/I splines then fitted a knot vector without a positive-width span
and failed inside SciPy at transform ("Need at least two internal knots").
The P-spline and tensor-product bases were all zero, and the cubic and
natural cubic bases silently emitted fewer columns than requested.

Such a feature now raises PretabDataError at fit in every spline family
that needs spread, as a constant feature does. The message keeps the
"1 sample" wording scikit-learn's check_fit2d_1sample expects.

This branch has not been deployed

No deployments
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.

1 participant