Skip to content

feat: Add adds/subtracts to Variable with parameter path resolution#248

Merged
anth-volk merged 1 commit intomainfrom
feat/add-adds-subtracts
Mar 11, 2026
Merged

feat: Add adds/subtracts to Variable with parameter path resolution#248
anth-volk merged 1 commit intomainfrom
feat/add-adds-subtracts

Conversation

@anth-volk
Copy link
Contributor

@anth-volk anth-volk commented Mar 6, 2026

Fixes #247

Summary

  • Adds adds and subtracts fields (list[str] | None) to the Variable Pydantic model
  • Extracts these from policyengine-core variable objects during US and UK model initialization
  • Resolves parameter path strings (e.g., "gov.hhs.tanf.cash.income.sources.earned") to list[str] so downstream consumers always get arrays
  • Adds 9 unit tests covering list adds, parameter-path resolution, subtracts, None cases, and cross-referencing validity

Test plan

  • TestVariableAddsSubtracts::test_us_variable_with_list_adds_has_list — direct list adds (e.g., employment_income)
  • TestVariableAddsSubtracts::test_us_variable_with_parameter_path_adds_resolves_to_list — parameter path resolution (e.g., household_state_benefits)
  • TestVariableAddsSubtracts::test_us_variable_without_adds_has_none — variables without adds
  • TestVariableAddsSubtracts::test_us_variable_without_subtracts_has_none — variables without subtracts
  • TestVariableAddsSubtracts::test_us_some_variables_have_adds — at least 50 US variables have adds
  • TestVariableAddsSubtracts::test_uk_variable_with_adds_has_list — UK variable with adds
  • TestVariableAddsSubtracts::test_uk_variable_without_adds_has_none — UK variable without adds
  • TestVariableAddsSubtracts::test_us_variable_with_subtracts_has_list — US variable with subtracts
  • TestVariableAddsSubtracts::test_adds_entries_are_valid_variable_names — adds entries reference real variables

🤖 Generated with Claude Code

…tion

Variables using declarative aggregation (adds/subtracts) now have these
fields populated on the Variable model. Parameter path strings are resolved
to list[str] at init time so downstream consumers always get arrays.

Closes #247

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anth-volk anth-volk marked this pull request as ready for review March 6, 2026 20:04
Copy link
Contributor

@nwoodruff-co nwoodruff-co left a comment

Choose a reason for hiding this comment

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

Why is this needed- and if so, should probably be proper references to other rows in the Variable table

@anth-volk
Copy link
Contributor Author

This is needed to build the results tree we use for nested household outputs. You make a fair point about row references, though I'll need to think through implementation. I wonder what the time and complexity costs of creating them would be, considering that you'd need to create rows that are within a given var's adds or subtracts first, then create the "consumers", so to speak.

@anth-volk
Copy link
Contributor Author

I did some looking into this and I can't envision an implementation where we don't have to algorithmically determine which params to load in first based on where they sit in the adds/subtracts tree, especially since they can nest pretty deeply in -us.

@anth-volk anth-volk merged commit fdb3cea into main Mar 11, 2026
3 checks passed
@anth-volk anth-volk deleted the feat/add-adds-subtracts branch March 11, 2026 21:18
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.

Add adds/subtracts fields to Variable model and resolve parameter paths

2 participants