Repository navigation
Conversation
taxable_income adds the gross nz_superannuation, and jobseeker_support with the new jobseeker_support_tax (Income Tax Act 2007, sections CF 1(1)(c) and (e)). jobseeker_support_tax is the income tax that the model assumes MSD pays on Jobseeker Support under section 350 of the Social Security Act 2018. It grosses the year's payment up on the personal tax schedule, apart from other income, and section 351(b)(iv) makes it the person's income. For a period that starts before 1 April 2022, taxable income keeps the old sources and raises an error for a person marked as a recipient of either benefit or given a nonzero amount of one. Part of #18. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- taxable_income reads a benefit amount stored for the period on the simulation's own branch, else on the branch it was made from, else on disk, and compares whole periods. Core's lookup read the default branch's amount in a named branch, and failed for a period-2022 calculation when either benefit had an input for a year that starts in April. - grossed_up_tax rejects a schedule with a NaN or infinite threshold, a NaN rate, or thresholds and rates of different shapes. - The income_tax documentation, the README and the docs describe income_tax as the year's liability before credits and jobseeker_support_tax as a separate estimate, whose difference can be negative. The README and the docs say income tax starts in 2021-22 and the benefits enter it in 2022-23. - New tests cover a linked couple's two Jobseeker shares, a partnered NZ Super recipient beside a working partner, a loss beside Jobseeker Support, branch, anchored-year and disk reads, and invalid schedules. - The Jobseeker Support rate description says the rates come before the income test, and the README's clause 1(d) example leaves out 2013 transferees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Agent-written for Max, by Claude Code for Max Ghenis. Answer to the first review, which requested changes at 3606387. I fixed each P1, P2 and P3 in 63e9c99. I reproduced every RAN witness at 3606387 first, and each result below comes from a run at 63e9c99 on this Mac. P1, the branch read. P1, a year that starts in April. The same Core defect reaches further than the guard, and P1, the tax MSD pays and the year's liability. The P1, NaN in the schedule. P1, a linked couple. P2, the partnered NZ Super case. The YAML case now gives the retiree a partner who earns $30,000. The retiree owes $3,386.47 and the partner $4,158; taxing the couple's $55,591.28 together would give $8,897.88. Summing taxable income over the household fails it. P2, the documentation. The README and the docs now say income tax starts in 2021-22 and that the two benefits enter it in 2022-23. The Jobseeker Support rate description says the rates come before the applicable income test, and the README's clause 1(d) example now leaves out people transferred to Jobseeker Support on 15 July 2013. P2, the test module. Its header now names the years: the inverse from 2021-22 to 2027-28, and simulations from 2022-23. P3, wording. The Your suggestion to tax supplied period-2022 amounts on the 2021-22 schedule is a design change beyond the findings, so this PR keeps the error. Checks. The two test files hold 67 cases, and the suite passes, 1,692 tests. The mutation table covers 43 changes, including your three survivors, and each fails at least one test. Ruff 0.16.7 flags only The second review of 63e9c99 is under way, alongside CI. |
- taxable_income decides whether a period that starts before 1 April 2022 has a benefit recipient from the receiving_nz_super and receiving_jobseeker_support flags alone. The supplied-amount check, which read Core's storage directly, is gone, and an amount given without a flag is left out, as on main. - grossed_up_tax sums each bracket's tax and its amount left after tax, finds the bracket by that amount, and raises when the tax on a finite amount overflows a float. A tiny rate keeps its tax, a rate just below one keeps a finite tax, and a large bracket keeps its small after-tax width. - jobseeker_support_tax raises a TypeError when a reform makes the income tax schedule anything other than a marginal-rate scale. - The documentation, README and changelog say the model assumes MSD pays the tax, and name the clause each couple rate comes from. - New tests cover a NaN rate set through a reform, an average-rate schedule, two grants on the clause 1(g)(i) rate, and the float limits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Agent-written for Max, by Claude Code for Max Ghenis. Answer to the second review, which requested changes at 63e9c99. 128f88b answers each finding, and #34 tracks the Core upgrade. Each result below comes from a run at 128f88b on this Mac, beside main at ba0a233 where it matters. P1s on the inherited, disk, ancestor, colon and neutralized reads. P1, a year that starts in April. This stays a Core 3.20.0 defect, and #33 still reaches it in more places than main. With either benefit set only for P1, a branch made after a calculation. This is Core-wide. On main as at 128f88b, calculating P1, the gross-up's arithmetic. P1, an average-rate schedule. P1, the two-grant clause. You are right, and my first reply was wrong to say both couples take the clause 1(j)(i) rate. A couple with one grant takes clause 1(j)(i), split half to each partner, and a couple with two takes clause 1(g)(i) for each. The comment and the description now say so. P1, the pooling mutations. You are right that P2, Core's private attributes and version range. The model no longer reads any private Core attribute. #34 asks for a lower bound in P2, the schedule contract. The P2, the README, tolerances and population wording. The README gives the thresholds to 2023-24 and from 2025-26, names 2024-25's composite schedule, and its clause 1(d) example now leaves out only the people clause 1(c) covers. The description gives each tolerance on its own: a cent for the YAML cases, $0.000001 for the inverse and 3 cents for simulations. The changelog and the documentation say a recipient stops the whole calculation. P3, voice and attribution. The changelog, README, labels and documentation now say the model assumes MSD pays the tax, use active subjects and sentence case, and drop the explanatory colons and semicolons you named. Checks. The two test files hold 70 cases, and the suite passes, 1,695 tests. The mutation table makes 43 changes, and each fails at least one test except one: searching for the bracket from the left gives the same tax at a boundary, since the lower bracket's whole excess times its rate over one minus its rate is that bracket's tax. Ruff 0.16.7 flags only A scoped third review of the nine P1s comes next, alongside CI. Edited after posting: the anchored-year paragraph now names the routes I tested, and it no longer lists the disk-only case as a limit, since Core 3.20.0 reaches it for a receipt flag only through private attributes. |
Agent-written for Max, by Claude Code for Max Ghenis.
Part of #18. This PR carries out steps 2 and 3 of its plan. It meets step 4 in the documentation only, since no variable gives income after tax yet, and step 5 for Jobseeker Support, whose rate metadata now says the rates come before the income test and that the model assumes MSD pays the tax on them. The Jobseeker Support variable already called its amount net cash and now names that assumption, and the NZ Super rates were already labelled gross. Main already reads a bare year as the tax year ending 31 March, which settles step 1. Step 6, the Working for Families income measure, follows in a separate PR.
What this fixes
taxable_incomeadded employment, self-employment and investment income and nothing else, so a person on NZ Superannuation or Jobseeker Support paid no income tax on it. The Income Tax Act 2007 makes both income: a main benefit under section CF 1(1)(c) and NZ Superannuation under section CF 1(1)(e).Changes
taxable_incomeaddsnz_superannuation, which the rates already give gross, from the 2022-23 tax year (period 2023).jobseeker_support_taxis the income tax that the model assumes MSD pays on Jobseeker Support. Section 350(2) of the Social Security Act 2018 lets MSD pay that tax to Inland Revenue instead of deducting it, section 350(3) computes it on the payment grossed up so that what remains after tax equals the payment, and section 351(b)(iv) makes it the person's income.taxable_incomeaddsjobseeker_supportand this tax.grossed_up_taxinverts the tax schedule in closed form, up to floating-point rounding. It adds up, bracket by bracket, the tax on each full bracket and the amount that bracket leaves after tax, finds the bracket whose amounts after tax hold the payment, and adds the tax at the bracket's threshold to the payment's excess over the bracket's lowest amount after tax, times the bracket's rate over one minus that rate. A payment at or below zero gives no tax, and a NaN gives NaN. It raises aValueErrorfor a schedule it cannot invert (thresholds and rates that are not one-dimensional or differ in shape, no brackets, a NaN or infinite threshold, a first threshold other than 0, thresholds that do not rise, or a rate that is NaN or outside [0, 1)) and for a tax too large for a 64-bit float. It reads the thresholds and rates as NumPy converts them to 64-bit floats and checks the converted arrays, which for the model's schedule are the brackets Core builds for the period.jobseeker_support_taxraises aTypeErrorwhen a reform makes the income tax schedule anything other than a marginal-rate scale, such as a linear average-rate scale, which the gross-up cannot invert.nz_superannuationandjobseeker_supportraise an error for everyone unless an amount is given, so taxable income keeps the three old sources and leaves out both benefits, as before. It raises aValueErrorfor the whole calculation whenreceiving_nz_superorreceiving_jobseeker_supportmarks anyone as a recipient. Core reads the two flags as it reads any input. An amount of either benefit given for such a period without a flag stays out of taxable income, as on main. Period 2022 still taxes other income as before.income_tax,jobseeker_support, the Jobseeker Support rates and the README now says that the model assumes MSD pays the tax on Jobseeker Support. It describesincome_taxas the year's liability before credits andjobseeker_support_taxas a separate estimate of what MSD pays. The README and the docs say that income tax starts in 2021-22 and that the two benefits enter it in 2022-23. The README now gives the schedule for each tax year, and its clause 1(d) example now leaves out the people clause 1(c) covers. The changelog fragment for the NZ Super rates no longer says that no variable readsnz_superannuation.Assumptions and limits
jobseeker_supporton the personal tax schedule for the tax year, apart from the person's other income. Section 350(3) uses the rate that the Commissioner determines for each payment, in consultation with MSD's chief executive, under section RD 11(3), so the tax on each payment can differ from this annual figure. For 2024-25, the annual gross-up uses the year's composite schedule.income_taxfrom benefits.income_tax - jobseeker_support_taxis the balance after MSD's payment, and it is negative when a loss brings the liability below that payment: $19,372.60 of Jobseeker Support beside a $40,000 self-employment loss gives $2,785.70 ofjobseeker_support_taxand noincome_tax.pyproject.tomlallows any version from 3.19.0. Core 3.20.0 lists a variable's stored periods by splitting each storage key at every colon, which misreads a key for a year that starts in a month other than January, such asyear:2025-04. When a calculation misses the requested period in memory while such a key is in memory, Core raises. On main,employment_incomegiven only foryear:2025-04fails for period 2022. This PR calculates the two benefits for periods from 2022-23, and reads the two receipt flags for earlier periods, so an input of either benefit or flag stored only for such a year makestaxable_incomeandincome_taxfail for those periods, where main returned. Core 3.30.3 fixed the parsing (Fix storage key parsing for anchored year periods policyengine-core#525), and Upgrade policyengine-core past two 3.20.0 defects #34 tracks the upgrade.employment_incomeafter its parent calculated $50,000 still returns $50,000 of taxable income. So a receipt flag or benefit set on a branch after its parent calculated taxable income leaves the parent's result in place. Give a branch its inputs before calculating on it or its parent. Core 3.33.0 changed this (Make set_input on a branch drop values calculated from the input it replaces policyengine-core#560), and Upgrade policyengine-core past two 3.20.0 defects #34 covers it too.family_incomestill leaves out both benefits, so Working for Families is unchanged.Tests
test_benefit_income_tax.yamlholds #18's cases 1 to 6 for 2026-27, to the cent, with each derivation from Table 1 in a comment:taxable_incomeincome_taxIt also covers a Jobseeker grant at the clause 1(d) rate, which gives case 4's figures; a $40,000 self-employment loss beside NZ Super, which gives 0; the same loss beside case 4's Jobseeker Support, which leaves $2,785.70 of
jobseeker_support_taxand noincome_tax; and NZ Super in 2022-23, which gives $3,917.98 of tax.The YAML cases compare to a cent.
test_benefit_income_tax.pychecks:grossed_up_taxgives, to $0.000001;taxable_incomelessjobseeker_support_taxis the payment andincome_taxlessjobseeker_support_taxis 0 for a person with no other income, to 3 cents, since a simulation stores 32-bit floats;jobseeker_support_taxunchanged, and that each person's payment is grossed up on its own;jobseeker_support_tax, with one grant (clause 1(j)(i), half to each) and with two (clause 1(g)(i) to each), and that a reform raising only the clause 1(g)(i) rate to $401 a week moves the couple with two grants to $20,852 and $3,099.52 each and leaves the couple with one grant where it was;ValueErrorfor a tax too large for a 64-bit float;ValueErrorfor each kind of schedule that cannot be inverted, including NaN and infinite values, shapes that differ, the 2024-25 schedule with a NaN rate, and the same NaN rate set by a reform through Core'sParameter.update, and theTypeErrorfor a reform that gives the schedule average rates;year:2021-07raises for that year.The two new test files hold 70 cases, and the suite passes, 1,695 tests. A mutation check makes 43 changes to
taxable_income,jobseeker_support_tax,jobseeker_supportand the 2024-25 rates (dropping each new source, flooring other income on its own, taxing a household's income together, the wrong start date, each period-2022 check removed, narrowed or widened, the wrong bracket, rate or sign in the inverse, 63e9c99's subtraction scheme and each of its parts, no zero, NaN or overflow handling, no scale-type check, each schedule check removed or loosened, grossing up wages with the benefit, pooling a couple's payments, no tax on a paid partner's share, no MSD tax beside a loss, paying two grants half the clause 1(j)(i) rate, and 12.8201% for 12.82%). Each fails at least one test except one: searching for the bracket from the left gives the same tax at a boundary, since the lower bracket's whole excess times its rate over one minus its rate is that bracket's tax. Locally, ruff 0.16.7'sruff format --check .flags onlyREADME.mdanddocs/index.md, as it does on main; CI's format job runs the repo's own ruff.Revisions
taxable_incomereads a stored benefit amount on the simulation's own branch first and compares whole periods;grossed_up_taxrejects NaN, infinite and mismatched schedules; the documentation describesincome_taxandjobseeker_support_taxas separate amounts whose difference can be negative; and new tests cover a linked couple, a working partner, a loss beside Jobseeker Support, branches, anchored years and disk storage.taxable_incomechecks only the receipt flags for a period before April 2022 and leaves a supplied amount out, as main does, in place of 63e9c99's private read of Core's storage.grossed_up_taxadds up each bracket's amount after tax and computes the tax directly, so a near-1 rate, a tiny rate or a large amount no longer loses or invents tax, andjobseeker_support_taxrejects a schedule that is not a marginal-rate scale. The description states Core 3.20.0's limits with the Core versions that fix them, the linked-couple test names the clause each grant takes and adds a reform that tells them apart, and the README gives the schedule for each tax year.axiom: no RuleSpec change (model formulas, tests and documentation)
🤖 Generated with Claude Code