Fix multi-entity trace truncation in PE derivation narratives#37
Merged
Conversation
The previous trace renderer took the first element of every OpenFisca trace value, which silently dropped every other entity's contribution. For joint households, the narrative would describe the head's row as the entire household: scenario_000's federal_income_tax_before_refundable_credits narrative reported "the household's only income is \$45,000 of self-employment income" — silently dropping the spouse's \$40,000 in wages. AGI \$81,821 magically appeared without an explanation that reconciled. Switch _value_repr and _is_zero to handle per-entity arrays as a unit: - length-1 collapses to a scalar (the common tax-unit/household case), - length>1 renders as ``sum (per entity: a, b, ...)`` for numeric values so the summariser sees both the total and the per-person decomposition, - booleans surface as ``[True, False]``, - ``_is_zero`` requires every entry to be zero before pruning a subtree. Regenerate all 2,188 US narratives (0 errors) and the dashboard + paper-snapshot data.json copies. Apply the cents-round pass that #36 introduced.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Reported by Max on scenario_000: the PolicyEngine derivation said "the household's only income is $45,000 of self-employment income" but the AGI it cited ($81,821) only reconciles if you include the spouse's $40,000 in wages. The narrative had silently dropped half the household.
Root cause
_value_reprand_is_zeroinpolicybench.case_reference_explanationswere callingvalue[0]on every OpenFisca trace value. Per-person variables likeirs_gross_incomecome through as length-N arrays ([45000, 40000]for[head, spouse]); we were taking the head's row and discarding the spouse's. This affected every multi-person scenario.Fix
Render multi-entity numeric arrays as
sum (per entity: a, b, ...)and require every entity to be zero before pruning a subtree:Booleans surface as
[True, False]. Length-1 arrays still collapse to a scalar so most renderings stay terse.Regenerated outputs
app/src/data.json+ the paper-snapshotdata.jsoncopies refreshed; manifest SHA256 updated.scenario_000 now reads:
Upstream
The same fix lives in
policyengine.derivations(policyengine.py#365). policybench currently ships its own copy of the renderer; once PE.py 4.5.2 publishes we'll switch to the upstream module.Test plan
uv run pytest -m "not slow"(251 passed)ruff check🤖 Generated with Claude Code