Skip to content

Guard mapped thresholds and NaN values; correct contrib tax brackets - #9934

Merged
MaxGhenis merged 10 commits into
mainfrom
mapped-threshold-and-nested-nan-guards
Nov 29, 2026
Merged

MaxGhenis merged 10 commits into
mainfrom
mapped-threshold-and-nested-nan-guards

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

We correct eleven dated values in two threshold series of the additional tax bracket contrib reform, and add tests that check mapped bracket thresholds and NaN parameter values.

For married separate filers, we end the reform's 33% band at half the joint upper threshold for 2026–2035, from $270,775 in 2026 to $323,625 in 2035. The earlier schedule gave separate filers the joint upper threshold for that band, which emptied the 35% band and ran the 33% band to $541,550 in 2026.

For single filers in 2022, we raise the top of the reform's 35% band from $539,000 to $539,900. With $539,900 or more of taxable income at ordinary rates, a single filer's tax at those rates falls by $18.

Sources

  • We compared the schedule's six finite bracket tops for single, joint, separate and head-of-household filers in each year from 2022 to 2035 with the January 2025 CSV that the US-CBO GitHub organization publishes. All 336 match. The organization's GitHub profile names the Congressional Budget Office and links to cbo.gov. The CBO website answered our request for the workbook with HTTP 403.
  • For 2022, the IRS puts the single-filer 35% upper threshold at $539,900 (Rev. Proc. 2021-45, Table 3).
  • For 2017, under the same seven rates the schedule uses from 2026, the IRS puts the separate-filer 33% upper threshold at $208,350, half the joint upper threshold of $416,700 (Rev. Proc. 2016-55, Table 1 and Table 4).

Invariants

  • The tests require mapped bracket thresholds to increase on every date a loaded threshold changes, uprated years included. They allow a repeated positive infinity for unused top brackets and reject a repeated negative infinity.
  • The mapped-threshold check rejects a NaN even when a filing status has a single active threshold.
  • For both shipped ordinary-income schedules, the tests require consecutive active rate keys and a positive-infinite threshold for the final active rate. They check each loaded rate or filing-status threshold change on dates with at least one active rate.
  • The tests also require a threshold for every active rate key before the final key, and they reject any date after the schedule's first active rate on which no rate is active.
  • The tests require the contrib schedule's separate-filer thresholds to equal half the joint thresholds on every date a loaded joint or separate threshold changes.
  • The tests reject Python float NaNs, NumPy float64 NaNs included, at the top level and inside lists, tuples, dictionary keys and values, sets and frozen sets.

The mapped-threshold test finds each table with a sibling rates node and consecutively numbered threshold keys. It fails unless it finds the federal income and capital gains tables and the additional tax bracket contrib table, and it checks every table it finds. The clamp regression recreates the old separate-filer inversion and checks tax inside the affected band.

Methodology choices

  • Keep the January 2025 projection as the basis for the hypothetical schedule and correct its dated thresholds.
  • Apply the half-joint check to the contrib schedule.
  • Check loaded parameters to cover uprated values.
  • Use a one-cent tolerance for the five new YAML cases: two 2022 single filers, two 2026 separate filers and one 2035 separate filer.

Tests

The five new YAML cases check tax at ordinary rates under the reform. We computed the earlier-threshold column by hand from main's thresholds and rates with the same bracket calculation, and the YAML cases assert the corrected column.

Year Filing status Taxable income Tax with earlier thresholds Tax with corrected thresholds
2022 Single $539,450 $162,569.50 $162,560.50
2022 Single $540,000 $162,773.00 $162,755.00
2026 Separate $300,000 $82,896.25 $83,480.75
2026 Separate $400,000 $115,896.25 $122,810.50
2035 Separate $400,000 $112,751.00 $115,862.05

The lone-NaN regression fails when we remove its check. The active-rate regression fails when we restore the threshold-only scan, which misses both the fixture's finite 2026 top and its 2027 rate gap.

Removing the check for missing intermediate thresholds makes test_income_bracket_top_guard_flags_missing_intermediate_threshold fail.
Removing the check for dates with no active rates after the schedule starts makes test_income_bracket_top_guard_flags_later_inactive_schedule fail.
Rejecting dates before the first active rate makes test_income_bracket_top_guard_allows_thresholds_before_rates fail.
Using a truthiness test to select active rates makes test_income_bracket_top_guard_flags_inactive_rates fail.

With main's contrib bracket table, the ordering test fails because the 2026 separate-filer thresholds fall from $541,550 at bracket 5 to $305,875 at bracket 6. The half-joint test rejects the same $541,550, since half the joint value comes to $270,775.

Removing the running-top clamp raises the recreated-inversion case's tax from $115,896.25 to $153,169.75 at $400,000 of taxable income. The mixed-status regression also fails, because the separate filer's tax at ordinary rates, $371,585.50, exceeds the baseline's $325,125.25.

We merged main at 8769cc75bc2efc7a3287834fc75a85c326343af6 in cc2a8bd42a.

At the final head, on PolicyEngine Core 3.38.0, the four changed test files passed:

File Result
test_parameter_scale_thresholds.py 25 passed
test_negative_main_rates_inverted_brackets.py 7 passed
test_additional_tax_bracket_unset_bracket.py 10 passed
additional_tax_bracket_reform.yaml 15 passed

CI passed at 9172e6ab: Pull request run.

Microsimulation impact

Only the additional tax bracket contrib reform reads the corrected schedule. The reform factory applies that reform when it finds gov.contrib.additional_tax_bracket.in_effect true in the years it checks, and the parameter defaults to false. The Tests table gives the reform's tax for five households; we have not estimated the reform's aggregate effect.

impact: none: only the default-off additional tax bracket contrib reform reads the corrected schedule

Axiom

axiom: n/a: test guards plus a contrib (hypothetical reform) parameter; no enacted-law provision changes.

🤖 Generated with Claude Code

MaxGhenis and others added 3 commits October 6, 2026 16:52
…racket

test_parameter_scale_thresholds only checked ParameterScale brackets, so
federal-style schedules (a `thresholds` node mapping bracket numbers to a
value per filing status, as gov.irs.income.bracket does) could repeat or
invert a threshold unnoticed, and nothing checked parameter values for
NaN, which YAML loads silently in scalars and inside list values.

The new mapped-threshold guard found one live inversion: the
additional_tax_bracket contrib reform's SEPARATE bracket-5 top for
2026-2035 copied the JOINT values (541,550 in 2026, above bracket 6's
305,875). #6235 fixed the same copy in gov.irs.income.bracket; the
contrib file kept it. The values are now half the joint thresholds, as
in every other bracket and year of the file and in #6235. Under the
reform, a separate filer's income from 270,775 to 305,875 was taxed at
33% instead of 35% in 2026.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_shipped_additional_tax_bracket_reform_is_clamped relied on the
shipped SEPARATE inversion, which the previous commit removed, so a
zero-income filer owed nothing with or without the clamp. The test now
recreates the old 541,550 bracket-5 top itself.

The mapped-threshold guard now requires a `rates` sibling, the node
tax_at_main_rates reads with `thresholds`, so a household-size table
named `thresholds` cannot be swept in. New unit cases show it flags a
repeated -inf and a NaN threshold, and the NaN test asserts it visited
parameters.

A second reform case covers the 39.6% band. The old data also taxed a
separate filer's income from 305,875 to 541,550 at 33% instead of 39.6%
(not only 270,775 to 305,875 at 33% instead of 35%, as the previous
commit said): taxable income of 400,000 owed 115,896.25, not 122,810.50.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round-2 review: a zero-income filer owes nothing under any loop that is
never negative per bracket, so the clamp test could not tell today's
unclamped form from the clamped one, nor notice if the recreated
inversion failed to apply. A separate filer with 400,000 of taxable
income now must owe exactly 115,896.25 under the recreated inversion:
122,810.50 if the inversion did not apply, other figures if the loop
did not clamp. (The previous commit's "owed nothing with or without the
clamp" held only for the old clip form.)

The table finder also skips an empty `thresholds` node, and the 2035
SEPARATE line loses a trailing space.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DTrim99

DTrim99 commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

PR Review: Guard federal-style bracket thresholds and NaN parameter values; fix the contrib MFS 33% bracket

PR #9934 (author: MaxGhenis, head f0d858eb83, merge-base 6b80a8e447). 5 files (+263/−18), 3 commits.

Summary

The PR does three things:

  • Fixes a contrib parameter. In the additional_tax_bracket reform, the married-filing-separately bracket-5 (33%) top for 2026–2035 was a copy of the joint values. In 2026 that was 541,550, above bracket 6's 305,875. The PR sets it to half the joint values: 270,775 in 2026 up to 323,625 in 2035. These are the same values Fix filing status and married variables as well as separate income tax brackets #6235 put in gov.irs.income.bracket in July 2025.
  • Adds a mapped-threshold guard. test_mapped_bracket_thresholds_strictly_increase finds every thresholds node numbered 1..N that sits beside a rates node. For each filing status, it requires the thresholds to strictly increase at every instant, including uprated years. A repeated +inf is allowed.
  • Adds a NaN guard. test_parameter_values_are_not_nan rejects NaN in any parameter value, whether it is a scalar or nested in a list.

The substance is right:

  • The new values match the cited source. CBO's January 2025 Tax Parameters workbook, which the parameter already cites, has the same ten numbers in its married-filing-separately row.
  • Expectations reproduce. Every YAML and Python expectation and every dollar figure in the PR body checks out by hand.
  • The tests fail before and pass after. With the merge-base contrib values, the guard fails with the inversion and both new YAML cases fail.
  • The guards survive a merge with current main. I resolved the conflicts and ran the four affected test files against the merged tree; all pass.
  • The guards are cheap. They take 0.09 s and 0.37 s.
  • CI is green.

Two should-fix items remain:

  • The branch now conflicts with main in two files.
  • The PR body still has placeholder "queued" sections, and it asks for that body to be used as the squash commit message.

Critical (must fix)

None.

Should address

1. The branch conflicts with main in two files, so GitHub can't merge it.

  • Status. GitHub reports mergeable: false, mergeable_state: dirty. git merge-tree --write-tree PolicyEngine/main f0d858eb83 reports CONFLICT (content) in:

  • Both conflicts are additive. Keep main's hypothesis imports, and keep main's new YAML case with this PR's two cases after it. The rest of the test module merges cleanly: main's calendar-date tests land mid-file and the PR's guards at the end.

  • I checked that resolution. I ran it locally with policyengine-core 3.32.27, main's locked version:

    Test file Result
    test_parameter_scale_thresholds.py (main's hypothesis and calendar-date tests plus both new guards) 18 passed
    additional_tax_bracket_reform.yaml 12 passed
    test_negative_main_rates_inverted_brackets.py 7 passed
    test_additional_tax_bracket_unset_bracket.py 9 passed

    So main's 211 newer commits, 83 of which touch parameters, add no NaN value and no repeated or inverted mapped threshold.

  • Fix: rebase or merge main, resolving the two conflicts as above.

2. The PR body still has placeholder sections and asks to be used as the squash commit body.

  • Where: the PR body, last edited 2026-10-06 22:37 UTC.
    • Under "Tests (fail before, pass after)": "Fail-before and pass-after runs are queued behind the shared test lock; this section is updated when they finish."
    • Under "Impact": "The reform microsimulation is queued behind the shared lock; this section is updated when it finishes."
    • It also says "Independent review: in progress".
    • The body asks: "Please use this PR's description for the squash body." If that happens as written, the squash commit on main will say results are still pending.
  • The results the body promises. I reproduced them at the head, with only bracket.yaml swapped back to the merge-base version:
    • Guard, before: test_mapped_bracket_thresholds_strictly_increase fails with gov.contrib.additional_tax_bracket.bracket.thresholds.*.SEPARATE: bracket 6 threshold 305,875 does not exceed bracket 5 threshold 541,550 at 2026-01-01 and 74 later instants to 2100-01-01.
    • YAML, before: 2 of the 11 cases fail. The $300,000 case gives 82,896.25 against 83,480.75. The $400,000 case gives 115,896.25 against 122,810.50.
    • After: with the PR's values, all of them pass.
  • Fix:
    • Replace the Tests placeholder with these results.
    • Either run the reform microsimulation and report it, or delete the Impact placeholder. The baseline is unchanged, so the paragraph isn't needed.
    • Drop the "Independent review: in progress" line before merge.

Suggestions

  1. The same contrib file still has another stale copy: 2022 single 37% bracket.
    • Where: policyengine_us/parameters/gov/contrib/additional_tax_bracket/bracket.yaml:760. It reads 2022-01-01: 539_000 under bracket 6 SINGLE.
    • The source. Rev. Proc. 2021-45, Table 3 (PDF p. 7): "Over $215,950 but not over $539,900 ... $49,335.50 plus 35% of the excess over $215,950". CBO's January 2025 workbook also has 539,900.
    • The federal file is already fixed. Correct the 2022 single 37% bracket threshold to $539,900 #9594 (2026-09-25) corrected gov.irs.income.bracket to 539,900. This is the same contrib-copy drift as Fix filing status and married variables as well as separate income tax brackets #6235 and this PR.
    • The guard can't catch it, because the value doesn't invert anything.
    • Effect. In 2022 reform runs, a single filer above $539,000 pays up to (37% − 35%) × 900 = $18 too much.
    • Cross-check. I compared all 336 bracket-top cells (4 statuses × 6 brackets × 2022–2035) in the file against the CBO workbook. This is the only mismatch.
    • Fix: change it to 539_900 here or in a follow-up.
  2. Optional stronger invariants for the mapped tables.
    • SEPARATE as half of JOINT. The ordering check caught this copy only because it happened to invert. A SEPARATE bracket copied from JOINT that doesn't invert would pass. SEPARATE == JOINT / 2 holds in the contrib schedule:

      • at every explicit instant of all 8 brackets;
      • for bracket 5, at every uprated instant through 2100.

      Checking it per instant would catch that class of error. Confirm it on the loaded values before applying it to gov.irs.income.bracket: that file's SEPARATE brackets 4–5 carry explicit 2027–2035 values where JOINT is uprated.

    • An infinite top bracket. Where rates and thresholds have the same length (the income schedules, not capital_gains), the last threshold should be +inf. tax_at_main_rates never taxes income above a finite top.

  3. Optional later-year test. Only 2026 is tested. The 2027–2035 values match CBO exactly and are exact halves of JOINT, but one case would pin them, such as 2035 or an uprated 2036. In 2036, SEPARATE brackets 4–6 are 184,775 / 329,975 / 372,750.
  4. The module's summary line is now too narrow. test_parameter_scale_thresholds.py still opens with "Parameter scales must not repeat a threshold at any instant." It now also holds the mapped-threshold and NaN guards, and the calendar-date guard after merging main. A broader first line, or a rename, would make the guards easier to find.

Verified correct

  • The new MFS bracket-5 values (bracket.yaml:683-692):
    • CBO. CBO, Tax Parameters and Effective Marginal Tax Rates, January 2025 (already cited in the node's reference), sheet "1. Tax Parameters", "Married filing separately", "Sixth rate begins at taxable income of", 2026–2035: 270775, 276525, 282100, 287700, 293375, 299175, 305100, 311150, 317325, 323625. These equal the PR's values exactly.
    • Single and joint. The "Single filers" and "Married filing jointly" sixth-rate rows are both 541550 … 647250. So SINGLE bracket 5 at 541,550 is correct, as the PR body says.
    • The values equal Fix filing status and married variables as well as separate income tax brackets #6235's gov.irs.income.bracket values, digit for digit.
  • The pre-TCJA structure the projection follows. Rev. Proc. 2016-55 (tax year 2017):
    • Table 1 (PDF p. 7): joint "Over $233,350 but not over $416,700 ... 33%".
    • Table 4 (PDF p. 9): separate "Over $116,675 but not over $208,350 ... 33%", then "Over $208,350 ... not over $235,350 ... 35%".
    • The separate 33% top is half the joint one (208,350 = 416,700 / 2).
  • SEPARATE is half of JOINT in every bracket and year of the file at the head. This was checked on the explicit YAML values for all 8 brackets. After uprating, bracket 5 stays an exact half through 2100, for example 329,975 / 659,950 in 2036.
  • Hand checks: 2026 separate filer under the reform, brackets 12,150 / 49,300 / 99,500 / 151,625 / 270,775 / 305,875.
    • $300,000: 1,215 + 5,572.50 + 12,550 + 14,595 + 39,319.50 + 0.35 × 29,225 = 83,480.75. Old data gives 33,932.50 + 0.33 × 148,375 = 82,896.25.
    • $400,000: 83,480.75 + 0.35 × 5,875 + 0.396 × 94,125 = 122,810.50.
    • Recreated inversion, clamped: 33,932.50 + 0.33 × 248,375 = 115,896.25. An unclamped loop would give 33,932.50 + 81,963.75 + 0.396 × 94,125 = 153,169.75, so the new assertion separates all three cases.
    • PR-body maximum gaps:
      • 2026: 144,931.80 − 128,675.25 = 16,256.55.
      • 2035: 173,217.80 − 153,788.25 = 19,429.55.
  • The mapped-threshold guard:
    • Tables found. It finds exactly four:

      • gov.irs.income.bracket.thresholds
      • gov.irs.capital_gains.thresholds
      • gov.contrib.additional_tax_bracket.bracket.thresholds
      • gov.contrib.harris.capital_gains.thresholds

      That matches the PR body. The rates sibling requirement keeps out the WA senior property-tax thresholds directory. The guard asserts both federal tables are found, so it can't pass vacuously.

    • Instants. It walks 84–88 instants per table, through 2100, including uprated years. It skips brackets that haven't started yet (None) and only exempts a repeated +inf.

    • Probe on the merged tree. Re-injecting 541,550 for 2026 is flagged. A NaN injected into gov.irs.income.bracket.thresholds.3.SINGLE is flagged by both guards.

    • Robustness. Error messages are deterministic, with no randomness. The test takes 0.09 s.

  • The NaN guard:
    • Coverage. It reaches scale bracket leaves too: in core 3.32.27, ParameterScaleBracket.get_descendants yields the threshold, amount and rate parameters. It also catches np.float64 NaN, which is a float subclass.
    • Types. Core's ALLOWED_PARAM_TYPES is (float, int, bool, type(None), typing.List), so scalars and lists cover every legal value.
    • Runtime. It takes 0.37 s.
  • The clamp test (test_negative_main_rates_inverted_brackets.py:196-239):
    • The scenario. It now recreates the old 541,550 top itself, scoped to 2026-01-01.2026-12-31.
    • The new check. The $400,000 assertion is what makes it discriminating. The zero-income assertions alone pass under any non-negative loop, as commit 3 notes.
  • Callers:
    • The parameter. Only reforms/additional_tax_bracket reads gov.contrib.additional_tax_bracket.bracket.
    • Other tests. test_additional_tax_bracket_unset_bracket.py compares two loop forms on the shipped parameters and passes on the merged tree.
    • Baseline. It is untouched.
  • Changelog:
    • changelog.d/mapped-threshold-and-nested-nan-guards.fixed.md is top-level and typed fixed.
    • It is accurate: it names both mis-taxed bands, 270,775–541,550 at 33%.
  • PR-body claims I checked are accurate:

Axiom line assessment

Valid. The line reads axiom: n/a: test guards plus a contrib (hypothetical reform) parameter; no enacted-law provision changes.

CI status

All 35 checks pass (gh pr checks 9934).

  • The run. Run 37541471491 (pull_request, 2026-10-06 22:34 UTC, head f0d858eb83) tested the head merged into main as it stood that day. main has moved more than 200 commits since.
  • After merging current main. Should 1 covers the conflicts. Once they're resolved, the guards and the affected test files pass locally against current main (18 + 12 + 7 + 9).
  • Partner tests. The PR touches none, and the Household API Partners job passes.

Branch status

Verdict: REQUEST_CHANGES

@DTrim99 DTrim99 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The ten new MFS values match the CBO Jan 2025 Table 1 'Sixth rate begins' row and are exact halves of JOINT. The guard catches injected inversions and NaN, all expectations check by hand, and the axiom n/a is valid. Two should items (see the comment above): (1) the branch conflicts with main in test_parameter_scale_thresholds.py and additional_tax_bracket_reform.yaml; both are additive, and a union resolution passes locally, so main's newer parameters violate neither guard; (2) the PR body still has the queued 'Tests' and 'Impact' placeholders and asks to be the squash message, so fill in the verified results. Also worth fixing: the stale 2022 SINGLE 539,000 in the same contrib file (should be 539,900).

MaxGhenis and others added 2 commits November 13, 2026 08:34
Keep the calendar-date checks and all contrib reform cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Correct the 2022 single threshold and cover a later reform year.
Check half-joint thresholds in the contrib schedule, infinite top
thresholds in ordinary income schedules, and NaN in nested containers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis MaxGhenis changed the title Guard federal-style bracket thresholds and NaN parameter values; fix the contrib MFS 33% bracket Guard mapped thresholds and NaN values; correct contrib tax brackets Nov 13, 2026
MaxGhenis and others added 5 commits November 28, 2026 21:04
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Require the contrib threshold table and describe the corrected band tops.

Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Describe the positive-infinity exception for mapped thresholds. State that NaN compares unequal to itself.

Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Require thresholds for active nonfinal rates and flag dates with no active rates after a schedule starts. Cover a zero rate and thresholds that predate the first rate.

Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis dismissed DTrim99’s stale review November 29, 2026 23:16

Agent-written for Max, by Claude Code for Max Ghenis. Answered at 9172e6a: the conflicts with main in test_parameter_scale_thresholds.py and additional_tax_bracket_reform.yaml were resolved as a union in cc2a8bd; the body's Tests and Impact sections now hold the verified results; and the 2022 SINGLE threshold reads 539,900 (bracket.yaml:760 and :841). An independent review approved 2f090df with no P0 or P1 findings, and CI passed at this head.

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by Claude Code for Max Ghenis.

Merge record for 9172e6ab676ad36e0a4a6c1d7e9d4b05b7cd5c0a:

  • Review: a Codex cloud task reviewed 2f090dfc in a scoped round 3 and approved it with no P0 or P1 findings (GPT-6.2 Sol at Extra High effort; chat https://chatgpt.com/local/6b0c9da1-1108-83ea-9aba-ec0b5e852007).
  • Since then, main was merged in with no conflicts (9172e6ab). Main's two later commits touch none of this PR's files.
  • CI: all 35 checks passed at this head (Pull request run).
  • Not verified: the contents of the CBO workbook behind the separate-filer values.
  • The earlier changes-requested review was answered and dismissed with a note. Only the required approving review blocked the merge, so it lands as an admin squash merge pinned to this head.

@MaxGhenis
MaxGhenis merged commit a529ee4 into main Nov 29, 2026
35 checks passed
@MaxGhenis
MaxGhenis deleted the mapped-threshold-and-nested-nan-guards branch November 29, 2026 23:16
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