Skip to content

core: reject reserved factor names (rep, error, verdict, …) instead of corrupting the statistics - #35

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/reserved-factor-names
Open

core: reject reserved factor names (rep, error, verdict, …) instead of corrupting the statistics#35
ChrisW09 wants to merge 1 commit into
mainfrom
fix/reserved-factor-names

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #5.

Ratings.to_records() renames factors colliding with bookkeeping columns to <name>_factor, but every stats consumer still looks up the original name from ratings.factors — which then resolves to the bookkeeping column. Verified consequences: a factor named "rep" (or "input_id", "verdict") crashes analysis_frame with ValueError: cannot insert rep, already exists; a factor named "error" silently merges configs per question and a real 5-vs-2 effect vanishes into "skipped (no variance in verdict)".

Rather than threading the rename map through five stats modules, this rejects reserved names up front — the issue's suggested cheapest fix:

  • Factor.__post_init__ raises with a clear message naming the reserved set (study-definition path),
  • Ratings.__post_init__ raises identically (library-mode path for directly built Ratings),
  • the to_records rename stays as a last-ditch guard.

The reserved tuple is declared as RESERVED_FACTOR_NAMES in study.py with cross-reference comments to Ratings._RESERVED (kept literal there to avoid an import cycle).

Test: full cafe-core suite — 109 passed (the 1 failure is pre-existing #4, fix in PR #34).

🤖 Generated with Claude Code

The stats layer looks up columns by factor name, but to_records renames
factors that collide with bookkeeping columns (input_id, rep, judge_rep,
verdict, reasoning, error) to '<name>_factor'. The lookup then resolves
to the bookkeeping column instead: a factor named 'rep' crashes
analysis_frame ('cannot insert rep, already exists'), and a factor named
'error' silently groups configs together and erases real effects (a
5-vs-2 effect vanished into 'no variance in verdict').

Validate at both entry points: Factor.__post_init__ (study definition)
and Ratings.__post_init__ (library mode), with a clear error naming the
reserved set.

Fixes #5

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

stats: factor names colliding with reserved columns ("rep", "error", "verdict", …) crash or silently corrupt results

1 participant