Skip to content

Derived _per_capita series are not rebuilt by reforms applied to a built system, and hold their value through a None total #9845

Open

Description

@MaxGhenis

add_per_capita_uprating (policyengine_us/tools/per_capita_uprating.py) derives each <national total>_per_capita series from its national total and the population series. In two cases a derived series falls out of step with its total. Both were run on the head of #9628 (743b6dfd3d, which is main at ea79c39fb7 plus that PR), and neither involves backdating.

1. A dict reform applied to a built system does not rebuild them

CountryTaxBenefitSystem.modify_parameters rebuilds the derived series after init. But two other paths set values through Parameter.update directly, never call modify_parameters, and so never rebuild them:

  • Reform.from_dict's apply (policyengine-core 3.32.15, reforms/reform.py);
  • the YAML test runner's inline reforms, which assign self.parameters = modifier(self.parameters) (tools/test_runner.py).
from policyengine_core.reforms import Reform
from policyengine_us.system import CountryTaxBenefitSystem, system

TOTAL = "calibration.gov.cbo.income_by_source.employment_income"
reform = {TOTAL: {"year:2020:1": 1}}
built = CountryTaxBenefitSystem(reform=reform).parameters
afterwards = Reform.from_dict(reform, country_id="us")(system).parameters
Total, 2020 employment_income_per_capita, 2020
Built with the reform 1 2.97 × 10⁻⁹
Applied to the built system 1 24,981.44 (the baseline value)

The exhaustive reform in #9628's tests touches 42,489 parameters. Under it, 1 of the 19 derived series differs between the two paths: employment_income_per_capita in 2018 is 37,207.11 when built with the reform and 24,804.74 when the reform is applied afterwards.

2. A total set to None holds the previous per-capita value

_per_capita_values skips any instant where the total is None (if total_value is None or not population_value: continue). So the derived series keeps the previous value through that instant instead of becoming undefined:

Year Total with {"year:2020:1": None} Per capita (reformed) Per capita (baseline)
2019 8,273,000,000,000 24,671.29 24,671.29
2020 None 24,671.29 24,981.44
2021 9,022,400,000,000 26,690.41 26,690.41

Found while reviewing #9628. Its new whole-tree test skips the derived series because of case 1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions