Skip to content

Raise clear error when uprating year is outside table range#352

Merged
MaxGhenis merged 2 commits intomainfrom
fix/uprating-end-year-guard
Apr 17, 2026
Merged

Raise clear error when uprating year is outside table range#352
MaxGhenis merged 2 commits intomainfrom
fix/uprating-end-year-guard

Conversation

@MaxGhenis
Copy link
Copy Markdown
Contributor

Summary

policyengine_uk_data/utils/uprating.py uses a hardcoded END_YEAR = 2034 but both uprate_values and uprate_dataset accepted any target_year (or start_year/end_year) without validation. Requesting a year past 2034 surfaced as a bare pandas KeyError deep in the call stack; requesting a year before 2020 silently read non-existent columns.

This PR adds a typed UpratingYearOutOfRangeError and validates every year argument at the top of uprate_values and uprate_dataset. The error message tells the caller to either regenerate the table with a later END_YEAR or pick a supported year.

No signature changes beyond adding a typed exception class in the module namespace.

Test plan

  • uv run pytest policyengine_uk_data/tests/test_uprating_range.py -q passes (rejects year above end, year below start, and accepts a supported year using a seeded tmp_path table).

Finding U5 from the bug hunt.

@MaxGhenis
Copy link
Copy Markdown
Contributor Author

Self-review: APPROVE. See /tmp/bug-hunt/reviews/uk-data-reviews.md for detail. (GitHub blocks self-approve, so leaving as comment.)

@MaxGhenis MaxGhenis merged commit 54ee554 into main Apr 17, 2026
3 checks passed
@MaxGhenis MaxGhenis deleted the fix/uprating-end-year-guard branch April 17, 2026 16:05
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