Skip to content

fix(vectors): clear error for an out-of-range layer in normalize_alpha / dose - #21

Merged
bamdadd merged 2 commits into
bamdadd:mainfrom
dchaudhari7177:fix/layer-range-error
Jul 20, 2026
Merged

fix(vectors): clear error for an out-of-range layer in normalize_alpha / dose#21
bamdadd merged 2 commits into
bamdadd:mainfrom
dchaudhari7177:fix/layer-range-error

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Problem

Requesting a layer that is not in the vector raised a bare KeyError: 999, which doesn't tell the user which layers exist.

Fix

Guard at the top of normalize_alpha (which dose() also goes through):

ValueError: layer 999 not in steering vector; available layers: [3, 7]

Tests

  • normalize_alpha(vec, layer=999, ...) and dose(vec, layer=999, ...) both raise the new ValueError naming the layer and listing available layers (2-layer vector)
  • valid-layer behaviour pinned unchanged (norm-5 vector, alpha 2 → by_vector_norm 10)

python -m pytest tests/test_vectors.py passes.

Fixes #20

…_alpha

A layer missing from the steering vector raised a bare KeyError with no
hint of which layers exist. Guard in normalize_alpha (dose() reaches it
through the same path) and name both the bad layer and the available ones.

Fixes bamdadd#20
@bamdadd

bamdadd commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Thanks for this — the change itself is good. The out-of-range layer now raises a clear, typed ValueError that names the bad layer and lists the available ones, dose is covered through normalize_alpha, and the tests pin both. That's exactly what #20 asked for.

The only thing standing between this and a merge is formatting: CI's ruff format --check wants two files reformatted (src/steerbench/vectors.py and tests/test_vectors.py). Nothing wrong with the logic, it's just whitespace/wrapping the formatter is opinionated about. One step should turn CI green:

uv run ruff format .
git commit -am "style: ruff format"
git push

Push that and the checks should go green; I'll merge as soon as they do. Ping me if anything's unclear.

If steerbench is useful to you, a star helps others find it and Watch will keep you posted — glad to have you contributing.

@bamdadd
bamdadd merged commit 3b1ab2c into bamdadd:main Jul 20, 2026
1 check passed
@bamdadd

bamdadd commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Applied the one formatting step for you (ruff format on the two files) so you weren't blocked waiting on it — nothing else was needed. Your fix is solid: the out-of-range layer now raises a clear ValueError that names the bad layer and lists the available ones, dose is covered through normalize_alpha, and the tests pin both paths. Merged, and it closes #20.

Two clean contributions in a row now — really glad to have you here. If steerbench is useful to you, a star helps others find it and Watch keeps you posted on new issues; would love more contributions whenever you're up for it.

dchaudhari7177 added a commit to dchaudhari7177/steerbench that referenced this pull request Aug 14, 2026
An invalid --effect-col reached the user as an uncaught ValueError from
mid-parse in report.py, exiting 1 with a traceback. The message content was
right, but the delivery was inconsistent with every other CLI input error --
the missing-CSV guards a few lines above, and bamdadd#21/bamdadd#22/bamdadd#23, all go through
parser.error() for a clean one-line message and exit 2.

Pre-validate the column against both sweep headers instead, next to the
existing existence checks. report.sweep_columns() splits the header read out
of _read_sweep_rows so the check does not duplicate the parse; the in-parse
guard stays as the library-level backstop for direct load_dose_curve callers.

Checking both CSVs matters because the column is read from each: a name only
one sweep carries now names which file is short.
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.

Clear error for an out-of-range layer in normalize_alpha / dose

3 participants