Skip to content

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

Merged
mkumar73 merged 2 commits into
OpenTabular:mainfrom
xillig:fix/spline-single-observed-value
Nov 27, 2026
Merged

mkumar73 merged 2 commits into
OpenTabular:mainfrom
xillig:fix/spline-single-observed-value

Conversation

@xillig

@xillig xillig commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

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.

xillig and others added 2 commits November 11, 2026 05:22
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.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mkumar73 mkumar73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xillig , changes are appropriate.

  • CI passed, merged conflicts resolved.

PR to be merged to main.

@mkumar73
mkumar73 merged commit 0bba697 into OpenTabular:main Nov 27, 2026
19 checks passed
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.

3 participants