Skip to content

Commit 714dd2b

Browse files
ChrisW09claude
andcommitted
fix(core): report output_dim, not min_output_dim, when it is too small
``_resolve_output_bounds`` reported every floor violation against ``min_output_dim``, but ``lo`` is set to ``output_dim`` on the non-adaptive branch. So setting ``output_dim=0`` blamed a parameter the caller had not touched -- and one that is ignored entirely when ``adaptive`` is False: Preprocessor(numerical_method="ple", output_dim=0) -> min_output_dim must be >= 1, got 0. Fix: raise min_output_dim to at least the family minimum. Following that advice would not have helped. Families that pre-validate ``output_dim`` themselves (cubicspline, bspline) already reported it correctly, so the two halves of the package disagreed. Name the parameter that produced the value. ple output_dim=0 -> output_dim must be >= 1, got 0. cubicspline output_dim=0 -> output_dim must be >= 3 for the cubic spline basis, got 0 adaptive, min_output_dim=0 -> min_output_dim must be >= 1, got 0. Closes #38 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 51c3043 commit 714dd2b

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

pretab/core/adaptive.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ def _resolve_output_bounds(
8888

8989
label = floor_label if floor_label is not None else str(floor)
9090
if lo < floor:
91+
# ``lo`` is ``output_dim`` on the non-adaptive branch and whenever no
92+
# explicit ``min_output_dim`` was supplied, so naming the parameter
93+
# unconditionally pointed users at a knob they had not set -- and one
94+
# that is ignored when ``adaptive`` is False.
95+
name = "min_output_dim" if self.adaptive and min_req is not None else "output_dim"
9196
raise InvalidParamError(
92-
f"min_output_dim must be >= {label}, got {lo}.\n"
93-
"Fix: raise min_output_dim to at least the family minimum."
97+
f"{name} must be >= {label}, got {lo}.\n"
98+
f"Fix: raise {name} to at least the family minimum."
9499
)
95100
if ceil is not None and hi > ceil:
96101
raise InvalidParamError(

tests/test_exceptions.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,38 @@ def test_preprocessor_unknown_categorical_method():
249249
with pytest.raises(InvalidParamError) as exc:
250250
Preprocessor(categorical_method="bogus").fit(df, y)
251251
assert isinstance(exc.value, ValueError)
252+
253+
254+
# --------------------------------------------------------------------------- #
255+
# The floor error must name the parameter the caller actually set.
256+
#
257+
# ``lo`` is ``output_dim`` on the non-adaptive branch, but the message always
258+
# said "min_output_dim" -- a knob the user had not touched, and one that is
259+
# ignored entirely when ``adaptive`` is False.
260+
# --------------------------------------------------------------------------- #
261+
def test_floor_error_names_output_dim_when_not_adaptive():
262+
rng = np.random.default_rng(0)
263+
frame = pd.DataFrame({"a": rng.normal(size=50)})
264+
265+
with pytest.raises(InvalidParamError, match="output_dim must be >= 1, got 0"):
266+
Preprocessor(numerical_method="ple", output_dim=0).fit(frame, rng.normal(size=50))
267+
268+
269+
def test_floor_error_does_not_mention_min_output_dim_when_not_adaptive():
270+
rng = np.random.default_rng(0)
271+
frame = pd.DataFrame({"a": rng.normal(size=50)})
272+
273+
with pytest.raises(InvalidParamError) as excinfo:
274+
Preprocessor(numerical_method="ple", output_dim=0).fit(frame, rng.normal(size=50))
275+
276+
assert "min_output_dim" not in str(excinfo.value)
277+
278+
279+
def test_floor_error_names_min_output_dim_when_it_was_set():
280+
from pretab.transformers import PLETransformer
281+
282+
rng = np.random.default_rng(0)
283+
X = rng.normal(size=(50, 1))
284+
285+
with pytest.raises(InvalidParamError, match="min_output_dim must be >= 1"):
286+
PLETransformer(output_dim=5, adaptive=True, min_output_dim=0).fit(X, rng.normal(size=50))

0 commit comments

Comments
 (0)