Skip to content

fix(core): report output_dim, not min_output_dim, when it is too small #38

Description

@ChrisW09

Summary

With adaptive=False, setting an output_dim below the family floor produces an error that
blames min_output_dim — a parameter the user never set, and one that is ignored in
non-adaptive mode.

Reproduction

import numpy as np, pandas as pd
from pretab import Preprocessor

df = pd.DataFrame({"a": np.random.default_rng(0).normal(size=50)})
y = np.random.default_rng(1).normal(size=50)

for method in ["ple", "cubicspline"]:
    try:
        Preprocessor(numerical_method=method, output_dim=0).fit(df, y)
    except Exception as e:
        print(f"{method:14} -> {str(e).splitlines()[0]}")
ple            -> min_output_dim must be >= 1, got 0.
cubicspline    -> output_dim must be >= 3 for the cubic spline basis, got 0

Both were given output_dim=0. The families that pre-validate output_dim themselves report
it correctly; those that rely on the shared bounds resolver do not.

The follow-up line compounds it: "Fix: raise min_output_dim to at least the family minimum"
— acting on that advice would not help, since min_output_dim is unused when
adaptive=False.

Expected

The message names the parameter the caller actually set.

Actual

min_output_dim is named whenever the floor check trips, regardless of which parameter
produced the offending value.

Root cause

pretab/core/adaptive.py:89-94:

label = floor_label if floor_label is not None else str(floor)
if lo < floor:
    raise InvalidParamError(
        f"min_output_dim must be >= {label}, got {lo}.\n"
        "Fix: raise min_output_dim to at least the family minimum."
    )

lo is set a few lines earlier to output_dim on the non-adaptive branch
(adaptive.py:84), so the message is only correct when adaptive=True and the user
supplied min_output_dim.

Suggested fix

Pick the name from the branch that produced lo:

if lo < floor:
    name = "min_output_dim" if self.adaptive and min_req is not None else "output_dim"
    raise InvalidParamError(
        f"{name} must be >= {label}, got {lo}.\n"
        f"Fix: raise {name} to at least the family minimum."
    )

Cosmetic, but it is the first thing a user sees when they mis-size a transformer, and it
currently points them at the wrong knob.

Environment

  • pretab 0.1.0 (main @ 51c3043)
  • Python 3.11.15, numpy 2.4.6, pandas 2.3.3, scikit-learn 1.9.0, scipy 1.17.1
  • macOS (darwin 25.5.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions