Malformed formula now raises a raw pandas KeyError, breaking the slow gate
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 124
- Forks
- 24
- Avg merge
- 19h 32m
- Merged PRs (30d)
- 60
Description
Found during the weekly audit-drift triage on 2026-08-24. Filing rather than
auto-healing: the fix is a decision about error contracts, not mechanical
healing.
Symptom
tests/test_hssm.py::test_transform_params_general[include4-IndexError] fails
on all three Python versions in the Remaining Slow batch of run
32692969571:
FAILED tests/test_hssm.py::test_transform_params_general[include4-IndexError]
- KeyError: 'invalid_formula'
with the raise coming straight out of pandas:
.venv/lib/python3.13/site-packages/pandas/core/indexes/base.py:3648: KeyError
The case feeds a deliberately malformed spec — {"name": "v", "formula": "invalid_formula"}, a string with no ~ — and asserts IndexError.
Cause
933c63c0 (#1227) added RHS-only formula shorthand: _prepare_formula_terms
now builds DesignMatrices, and the code comments that "HSSM accepts both
full formulas and RHS-only shorthand."
So "invalid_formula" is no longer a malformed formula. It is read as valid
RHS shorthand — effectively v ~ invalid_formula — and formulae then looks up
a column of that name, which pandas rejects with KeyError.
The slow suite was green on 2026-08-17 and #1227 landed 2026-08-24 00:03, just
before the 05:17 run that first showed this.
Why it needs a decision
Both the old and new exceptions are accidents rather than contracts. The old
IndexError came from indexing the result of splitting on ~; the new
KeyError comes from a dataframe lookup. The test was asserting an
implementation artifact, so "just update the expected exception to KeyError"
would preserve that mistake and make the error message worse — a user who
typos a formula now gets a bare pandas KeyError naming their typo, with no
indication that a formula was being parsed.
Suggested direction, for a maintainer to confirm:
- validate in
_prepare_formula_termsthat every RHS term resolves against
the data, and raise aValueErrornaming the unresolved term and the
parameter it belongs to; - assert that error in the test instead of either incidental type.
Deliberately not fixed here — picking the exception type and message is an API
choice.
Scope note
This is one of two independent breaks in the 08-24 slow run. The other six
failing legs were collection errors from stale tests/slow/ paths, fixed
mechanically in #1241. This issue covers the remaining three Remaining Slow
legs, which #1241 will not fix.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with _prepare_formula_terms and tests/test_hssm.py::test_transform_params_general[include4-IndexError], then review the RHS-only shorthand change from #1227. Run the named test to reproduce the raw pandas KeyError. Done means the maintainer-approved error contract is implemented and the test asserts a stable, informative exception for unresolved formula terms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100