Skip to content

fix: raise typed exceptions instead of asserts in modifier validation#2714

Open
henryiii wants to merge 1 commit into
mainfrom
fix/modifier-validation-errors
Open

fix: raise typed exceptions instead of asserts in modifier validation#2714
henryiii wants to merge 1 commit into
mainfrom
fix/modifier-validation-errors

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Part of the code review in #2706.

Summary

  • Replace assert self.interpcode in [...] in histosys_combined.__init__ and normsys_combined.__init__ with raise InvalidInterpCode(msg) so the check is never silently dropped under python -O
  • Replace assert (mask_this_sample == masks[modname]).all() in staterror_builder.finalize with raise InvalidModel(msg) naming the offending modifier, guarding the real invariant that shared staterror parameters must have identical bin masks across samples
  • Add 8 new parametrized tests in tests/test_modifiers.py covering invalid interpcode values for both histosys and normsys

Test plan

  • pytest tests/test_modifiers.py tests/test_pdf.py tests/test_interpolate.py — 144 passed, 6 skipped
  • prek -a --quiet (ruff + pre-commit) — clean
  • test_histosys_invalid_interpcode parametrized over ["code1", "code4", "code3", "bad"] all raise InvalidInterpCode
  • test_normsys_invalid_interpcode parametrized over ["code0", "code2", "code4p", "bad"] all raise InvalidInterpCode

🤖 Generated with Claude Code

Replace bare `assert` statements in histosys_combined, normsys_combined,
and staterror_builder with typed exceptions (InvalidInterpCode /
InvalidModel) so validation is never silently bypassed under `python -O`.
Add tests covering invalid interpcode values for both modifier types.

Assisted-by: ClaudeCode:claude-sonnet-4.6
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@henryiii, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 55 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7db1c19e-ab7a-4444-ae80-174c6352e2c5

📥 Commits

Reviewing files that changed from the base of the PR and between 0e54a51 and 021236a.

📒 Files selected for processing (4)
  • src/pyhf/modifiers/histosys.py
  • src/pyhf/modifiers/normsys.py
  • src/pyhf/modifiers/staterror.py
  • tests/test_modifiers.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@henryiii henryiii marked this pull request as ready for review June 12, 2026 17:56
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.38%. Comparing base (0e54a51) to head (021236a).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/pyhf/modifiers/staterror.py 20.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2714      +/-   ##
==========================================
- Coverage   98.28%   96.38%   -1.90%     
==========================================
  Files          65       65              
  Lines        4305     4313       +8     
  Branches      465      468       +3     
==========================================
- Hits         4231     4157      -74     
- Misses         46      122      +76     
- Partials       28       34       +6     
Flag Coverage Δ
contrib ?
doctest ?
unittests-3.10 ?
unittests-3.11 96.38% <69.23%> (-0.09%) ⬇️
unittests-3.12 ?
unittests-3.13 ?
unittests-3.9 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant