You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consolidate economic impact analysis into shared compute functions #263
The economic impact analysis logic (decile impacts, budget summary, program statistics, poverty, inequality) is currently duplicated between the US and UK analysis.py files, and depends on country-specific string checks scattered throughout the code. This makes it hard to maintain, test, and extend to new countries.
Solution
Introduce shared, country-agnostic compute functions and a CountryConfig frozen dataclass that encapsulates all country-specific parameters:
CountryConfig (outputs/country_config.py): Frozen dataclass with US_CONFIG and UK_CONFIG singletons holding income variables, program definitions, budget variables, poverty variables, and inequality settings.
BudgetSummaryItem + compute_budget_summary() (outputs/budget_summary.py): Computes baseline/reform/change totals for budget variables using Aggregate.
Re-scoping after the PR #260 review: most of the consolidation this issue asked for has happened — both countries' economic_impact_analysis are now thin orchestrators over shared convenience functions in policyengine.outputs (decile impacts, intra-decile, poverty, inequality, LSR, cliffs; see docs/impact-analysis.md "Composing manually").
The residual duplication is narrow and concrete:
_validate_program_statistics_config — us/analysis.py:104 and uk/analysis.py:112, identical except the country word and the US_PROGRAMS/UK_PROGRAMS reference
_format_missing_program_variables and the config-error message builders — identical
the program-statistics build loop inside each economic_impact_analysis — identical but for the programs dict
Plan: extract validate_program_statistics_config(programs, baseline, reform, country_label) and build_program_statistics(programs, baseline, reform) into policyengine.outputs.program_statistics, call from both country files. Explicitly NOT adopting a strategy protocol or a unified cross-country result container — the country containers deliberately diverge (UK wealth-decile outputs), which is what overtook PR #260's design.
Activity
MaxGhenis commentedon Jul 7, 2026
Re-scoping after the PR #260 review: most of the consolidation this issue asked for has happened — both countries'
economic_impact_analysisare now thin orchestrators over shared convenience functions inpolicyengine.outputs(decile impacts, intra-decile, poverty, inequality, LSR, cliffs; see docs/impact-analysis.md "Composing manually").The residual duplication is narrow and concrete:
_validate_program_statistics_config—us/analysis.py:104anduk/analysis.py:112, identical except the country word and theUS_PROGRAMS/UK_PROGRAMSreference_format_missing_program_variablesand the config-error message builders — identicaleconomic_impact_analysis— identical but for the programs dictPlan: extract
validate_program_statistics_config(programs, baseline, reform, country_label)andbuild_program_statistics(programs, baseline, reform)intopolicyengine.outputs.program_statistics, call from both country files. Explicitly NOT adopting a strategy protocol or a unified cross-country result container — the country containers deliberately diverge (UK wealth-decile outputs), which is what overtook PR #260's design.Fresh PR to follow shortly.