Skip to content

Derive US program-statistics entity from variable metadata#342

Merged
vahid-ahmadi merged 3 commits into
mainfrom
program-specs-derive-entity
May 11, 2026
Merged

Derive US program-statistics entity from variable metadata#342
vahid-ahmadi merged 3 commits into
mainfrom
program-specs-derive-entity

Conversation

@vahid-ahmadi
Copy link
Copy Markdown
Contributor

Refs #326. Smaller follow-up on top of merged #327. Replaces #334.

Summary

  • Drop the duplicated entity field from US_PROGRAMS. Entity is now derived from model_version.get_variable(name).entity at runtime, so the program list cannot silently drift when policyengine-us moves a variable between entities.
  • Keeps the "missing outputs" check that Fix US program statistics variable mappings #327 added in _validate_program_statistics_config (variable must be both defined in the model and materialized in the simulation outputs).
  • Adds test_us_programs_entities_match_model_metadata so a typo or rename in US_PROGRAMS is caught at test time, not at simulation time.

Why this instead of #334

#334 was authored before #327 landed and (a) is severely behind main, (b) drops the materialized-outputs check from #327, and (c) introduced a programs.py module / ProgramSpec dataclasses that aren't load-bearing for the entity-derivation goal. This PR keeps only the durable improvement and stays minimal.

Test plan

  • pytest tests/test_us_program_statistics.py (covers entity derivation in economic_impact_analysis and the new metadata-match test).
  • pytest tests/test_aggregate.py tests/test_change_aggregate.py still passes.

🤖 Generated with Claude Code

Replace the duplicated entity field in the ``US_PROGRAMS`` dict with a
metadata-driven lookup via ``model_version.get_variable(name).entity``,
so the program list cannot silently drift when policyengine-us moves a
variable between entities. The "missing outputs" check from #327 is
preserved.

Refs #326. Closes #334 (smaller follow-up on top of merged #327).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…tadata

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vahid-ahmadi vahid-ahmadi requested a review from anth-volk May 7, 2026 12:34
@vahid-ahmadi vahid-ahmadi self-assigned this May 7, 2026
Copy link
Copy Markdown
Contributor

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but I'd prefer is_tax remain a key. It's unclear to me what US_PROGRAMS actually represents short of reading the comments.

Addresses review feedback on #342: restore is_tax as a named key inside
each program's metadata dict so US_PROGRAMS remains self-documenting.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vahid-ahmadi vahid-ahmadi requested a review from anth-volk May 11, 2026 13:42
@vahid-ahmadi vahid-ahmadi merged commit befcc13 into main May 11, 2026
11 checks passed
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.

2 participants