Add UK detailed budget program statistics#359
Conversation
|
@vahid-ahmadi I requested your review here. Could you specifically check whether the UK programs added in this PR align with the programs currently in use in the UK model/reporting flow, especially the |
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Approving. The four new programs (fuel_duty, state_pension, ni_employer, tax_credits) bring economic_impact_analysis(...).program_statistics to parity with policyengine-app's UKDetailedPrograms schema (src/schemas/societyWideModules.js). Entities, is_tax flags, and entity_variables wiring all line up. ProgramStatistics.run() itself is unchanged — this is pure additive wiring plus a pre-flight validation helper.
Test pattern is a nice step up from #358: the mocked simulation builds real MicroDataFrame / UKYearData / PolicyEngineUKDataset objects, with monkeypatching limited to Simulation.ensure and the unrelated non-program outputs.
Non-blocking suggestions for follow-up:
- Hoist
resolve_entity_variables(simulation)out of the program loop in_validate_program_statistics_config— it currently runs once per program × 2 simulations and returns the full dict each time. - Tighten the
UK_PROGRAMStype hint —dict[str, dict[str, bool]]or aTypedDictwould self-document. tax_creditsoverlap withworking_tax_credit+child_tax_credit— matches the legacy app behavior (the app only consumestax_creditsfromUKDetailedPrograms), but worth either dropping the disaggregated rows or marking them with anoverlapping=Trueflag in the data structure rather than relying on the PR description comment alone. Today a downstream consumer that naively sums allprogram_statisticsrows will double-count._format_missing_program_variablesis a one-liner used once — could be inlined.- No example update in
examples/— small miss. - Schema asymmetry —
wealth_decile_impacts/program-stats list remains UK-only onPolicyReformAnalysis. Same follow-up as flagged on #358.
80a4147 to
1646113
Compare
Fixes #352
Summary
ProgramStatisticscoverage for detailed-budget parity by addingfuel_duty,state_pension,ni_employer, andtax_credits.extra_variables.economic_impact_analysis()wiring test with non-program outputs stubbed.Notes
tax_creditsintentionally overlaps withworking_tax_creditandchild_tax_credit; downstream budget adapters should choose the rows they need rather than summing all UK program-statistics rows.Tests
uv run --extra dev python -m pytest tests/test_uk_program_statistics.py tests/test_us_program_statistics.py -quv run ruff check tests/test_uk_program_statistics.py src/policyengine/tax_benefit_models/uk/analysis.py src/policyengine/tax_benefit_models/uk/model.pyuv run ruff format --check tests/test_uk_program_statistics.py src/policyengine/tax_benefit_models/uk/analysis.py src/policyengine/tax_benefit_models/uk/model.py