Consolidate economic impact analysis into shared compute functions#260
Open
Consolidate economic impact analysis into shared compute functions#260
Conversation
…ary, and poverty demographics Fixes #258 - Add BudgetSummaryItem output and compute_budget_summary() for per-variable budget analysis - Add CountryConfig strategy pattern (US_CONFIG, UK_CONFIG) replacing country conditionals - Add compute_decile_impacts() accepting already-run simulations - Add compute_program_statistics() shared function for both US and UK - Add PolicyReformAnalysis unified result container - Fix US program names and entities to match API (employee_payroll_tax, ssi on spm_unit) - Add intra-decile impacts, poverty by demographics (age/gender/race) to analysis - Fix StopIteration crashes in Aggregate/ChangeAggregate with clear ValueError messages - Add model_rebuild() for ProgramStatistics/ProgrammeStatistics and BudgetSummaryItem - Update outputs __init__.py exports Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add model_rebuild() for PolicyReformAnalysis in both US and UK __init__.py to resolve BudgetSummaryItem forward reference (TYPE_CHECKING import) - Fix test_aggregate to expect ValueError instead of StopIteration - Fix example script bp.metric → bp.poverty_type to match Poverty class Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix DecileImpact.run() StopIteration bug, move inline imports to top-level, improve exception logging in compute_program_statistics, use model_construct in compute_decile_impacts, and add 11 tests for the new economic impact output modules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ee14d76 to
3f95127
Compare
Contributor
Author
|
Related to #256 |
nikhilwoodruff
requested changes
Mar 19, 2026
| inequality_entity="household", | ||
| ) | ||
|
|
||
| UK_CONFIG = CountryConfig( |
Collaborator
There was a problem hiding this comment.
Against this- isn't this the point of putting this as properties of tax_benefit_model? and also introduces inconsistency with basemodels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #263
Summary
CountryConfigfrozen dataclass withUS_CONFIG/UK_CONFIGsingletons encapsulating all country-specific parameters (income variables, programs, budget variables, poverty variables, inequality settings)compute_budget_summary(),compute_program_statistics(),compute_decile_impacts(), andPolicyReformAnalysisresult containereconomic_impact_analysis()to use shared functions withUS_CONFIGDecileImpact.run()StopIterationbug (barenext()→next(..., None)+ValueError)us/analysis.pycompute_program_statisticswith full tracebackmodel_rebuild()forProgramStatistics,BudgetSummaryItem,PolicyReformAnalysisCountryConfig,compute_decile_impacts,DecileImpacterror handling, andChangeAggregateerror handlingTest plan
test_economic_impact_outputs.pypassruff formatandruff checkpass with zero issues🤖 Generated with Claude Code