Skip to content

Require policyengine-core 3.38.0 - #35

Draft
MaxGhenis wants to merge 3 commits into
mainfrom
core-3-38
Draft

MaxGhenis wants to merge 3 commits into
mainfrom
core-3-38

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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

Fixes #34.

What changes

  • pyproject.toml requires policyengine-core 3.38.0 or later, and uv.lock pins 3.38.0, the latest release on PyPI, from 27 November 2026. The lock moves no other package.
  • test_core_version.py checks the Core behaviour that the model relies on, and each test's comment says how 3.20.0 behaved.
    • Wages given only for year:2025-04 leave period 2022's income tax at $0, where 3.20.0 raised "got: 'year'".
    • A situation dict accepts wages for year:2025-04, reads back the $10,000 and gives $8,020 of tax for 2022, where 3.20.0 refused the key.
    • A branch made after its parent calculated income_tax reads its own $60,000 of wages and gives $10,220.50 of tax, and the parent keeps $7,658. On 3.20.0 the branch kept the parent's $50,000.
    • A branch of a branch reads its parent's $60,000, and a sibling branch reads the root's $50,000.
    • A simulation reads no wages that its holder stores under another branch's name, where 3.20.0 read $60,000 and gave $10,220.50 of tax.
    • The test sets a memory limit after it builds the simulation. The wages then sit on disk and out of memory, age stays in memory, and the tax stays $8,020. On 3.20.0 the limit left the wages in memory, so the test fails before it calculates.
    • With wages for 2022 and 2030, period 2027 carries over the 2022 wages and gives $7,658 of tax.
    • After a calculation, an update in place that sets the first rate to 0 reaches a new simulation, which owes $6,020. On 3.20.0 it still owed $7,658.
    • A reform that sets the first rate to 0 for "2026-04-01.2027-03-31" gives $6,020 of tax for 2027 and $7,658 for 2028, on both Cores. Keyed by "2027", the same reform gives $6,020 for both years.
    • Core refuses NaN in an input to a float or int variable, and an In-Work Tax Credit earner status it does not recognise.
    • Core refuses a year that starts mid-month in set_input and in a fresh calculation.
    • Two strict xfail tests record the mid-month behaviour that Core 3.38.0 keeps (below).
  • Tests in four files fed NaN through an input to check how the formulas treat it. They now store NaN as a value Core calculated, through store_as_calculated in tests/calculated.py. Each stored NaN replaces a nonzero input or reads back as NaN, so a helper that stored nothing fails all 20 cases that call it, in seven test functions.
  • Four parametrized cases gave the Jobseeker Support and NZ Super tests a year that starts on 31 March 2022, 2025 or 2026. Core now refuses such a year, and the cases are gone. The Jobseeker Support tests now read the clause 1(d) rate from the parameter on 1 April 2022, 31 March 2026 and 1 April 2026, and both files check that no rate is in force on 31 March 2022. The NZ Super tests already read each rate on 31 March and 1 April of each rate year.
  • The documentation of four amounts in Jobseeker Support and the Accommodation Supplement says that only a calculation can supply a NaN amount, since Core refuses NaN in a numeric input, and how the formula treats it.

Results that change for inputs Core 3.20.0 accepted

  • An earlier input carries over to a period before a later input. With wages given for 2022 and 2030, 3.20.0 gave 2027 no wages and $0 of tax.
  • A branch of a branch reads its parent's input. When the root also held wages, 3.20.0 gave the nested branch the root's $50,000 and $7,658 of tax.
  • A simulation reads no input that its holder stores under another branch's name. 3.20.0 read such an input when the simulation's own branch had none.
  • A parameter updated in place after a calculation reaches a new simulation. 3.20.0 kept the value it had already read.
  • Reform.from_dict applies a value keyed by a bare year or date from that date onward (Core 3.29.2). Keyed by "2027", the reform above gave 2028 the full $7,658 on 3.20.0. A range such as "2026-04-01.2027-03-31" limits a reform to one tax year on both Cores.
  • Core refuses an In-Work Tax Credit earner status it does not recognise, which 3.20.0 stored as automatic, and NaN in a float or int input, which 3.20.0 accepted. A Boolean input such as receiving_nz_super still reads NaN as true on both Cores.
  • The first review also reported that 3.20.0 attached family income to the wrong people in flat datasets with reversed or nonconsecutive family IDs. No check here reproduces that case.
  • A fresh calculation for a year that starts mid-month raises, where 3.20.0 gave the rate on its start date ($26,000 of Jobseeker Support in a probe with a reform that applies on 31 March 2026 alone).

Mid-month years that Core 3.38.0 still accepts

Core keys a stored value by the period's string form, which drops the day of a year that starts mid-month. policyengine-core#526 tracks the fix. Until then:

  • A situation dict stores wages given for year:2026-03-31 under year:2026-03 without an error. Core 3.20.0 raised for this key, as it did for any key with a colon.
  • A calculation for year:2026-03-31 after one for year:2026-03-01 returns the 1 March result, $18,788.64 in the probe above, as 3.20.0 also did.

Each xfail test passes if Core either refuses the year or keeps it apart from the first of its month, so it fails while Core behaves this way. Once Core changes in either way, the test passes, which strict xfail reports as a failure, and the mark comes off.

Checks

  • The full suite passes on Core 3.38.0, 1,808 tests, with the two expected failures. Its one warning, an infinite cost minus an infinite base rate in the Accommodation Supplement, also appears on main.
  • On Core 3.20.0, 13 of the 15 tests in test_core_version.py fail, each where its comment says. The range-keyed reform passes, and the cached mid-month test fails at its last check, as expected.
  • With Core patched to refuse a year that starts mid-month in the situation builder and at the start of a calculation, both xfail tests pass, so strict xfail fails them. On 3.38.0 each fails at its last check.
  • With Core's situation builder patched to drop the year:2025-04 wages, the situation-dict test fails. It reads the $50,000 carried over from 2022.
  • Main's tests make no branch apart from the new ones, so Core 3.24.0's change to the branch that a missing value falls back to reaches none of them. The reform tests in eight files pass on 3.38.0.
  • Ruff 0.15.5, the version the lock pins, finds nothing to reformat.

Revisions

  • 009be08 is the first version.
  • fae567a answers the first review. The situation-dict test reads back the April wages, and the disk test checks where Core keeps the wages and age. New tests cover a nested and a sibling branch, carry-over past a later input, reform keys, an unknown earner status, a fresh mid-month calculation and the rates on 31 March and 1 April. Two strict xfail tests record the mid-month behaviour that policyengine-core#526 tracks. The changelog, the documentation and this description limit Core's NaN refusal to numeric inputs, give the results that change, describe the mid-month behaviour Core keeps, and count four files and 20 cases for the NaN helper.
  • 25d4f8f corrects fae567a. Each xfail test now passes if Core either refuses a year that starts mid-month or keeps it apart, so it comes off under policyengine-core#526's fix. New tests cover an input stored under another branch's name and a rate updated in place after a calculation. The changelog states when 3.20.0 gave a nested branch the root's input, names set_input and a fresh calculation as the routes that refuse a year that starts mid-month, and says that 3.20.0 applied a bare date key for that day alone.

axiom: no RuleSpec change (Core dependency and tests)

🤖 Generated with Claude Code

Core 3.20.0, which the lock pinned, broke calculations for other periods
when an input was stored for a year that starts in April, refused such a
year in a situation dict, kept a branch's results calculated from its
parent's input after the branch replaced that input, and recursed without
end on a value kept only on disk. Core 3.38.0 fixes all four, and
test_core_version.py checks each one.

Core 3.26.6 and later refuse an input that contains NaN, and 3.30.3 and
later refuse a year that starts mid-month. The tests that check how the
formulas treat NaN now store it as a calculated value, through
store_as_calculated, and the tests that gave a year starting on 31 March
are gone. Two tests check the refusals.

Fixes #34.

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

Copy link
Copy Markdown
Contributor Author

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

Round 1 review of 009be08, run as a Codex cloud task: https://chatgpt.com/local/6b0ef18c-825c-83e9-921b-fd35ee7270c0. The page shows GPT-6.2 Sol at Extra High effort. Verdict: REQUEST_CHANGES, with five P1s, two P2s and one P3.

  • P1: a situation dict moves an input for a year that starts on 31 March to a year that starts on 1 March, and a calculation for such a year after one for 1 March returns the 1 March result, so the changelog's claim that Core refuses such a year holds only for set_input and a cold calculation.
  • P1: the situation-dict test for a year from April passes even if Core drops the April wages.
  • P1: Core 3.29.2 makes a Reform.from_dict value keyed by a bare year or date apply from then on, which changes later years for an existing bounded edit, and neither the changelog nor a test covers it.
  • P1: the description miscounts the NaN changes, which cover four files and 20 cases that call the helper.
  • P1: Core refuses NaN only for numeric inputs, so the blanket claim is false.
  • P2: the disk test fails on Core 3.20.0 at holder allocation, before it reaches the old recursion.
  • P2: the branch test leaves nested inheritance and isolation from an unrelated branch untested.
  • P3: two passages use passive wording.

The review found the lock moves only Core, all six new tests pass on 3.38.0 and fail on 3.20.0, and make test gives 1,796 passed with one warning. It ran on Linux and lists no check it could not run. It also lists results that change for inputs main admitted, which the description will now state. I'll answer each finding in a follow-up commit.

The situation-dict test reads back the April wages, and the disk test
checks that Core keeps the wages on disk and age in memory. New tests
cover a nested and a sibling branch, carry-over past a later input,
reform keys, an unknown earner status, a fresh mid-month calculation, and
the Jobseeker Support and NZ Super rates on 31 March and 1 April. Two
strict xfail tests record the mid-month behaviour that
policyengine-core#526 tracks. The changelog and the documentation limit
Core's NaN refusal to numeric inputs and give the results that change.

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

Copy link
Copy Markdown
Contributor Author

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

Answer to the first review of 009be08. fae567a answers each finding, and the full suite passes on Core 3.38.0, 1,806 tests, with two expected failures. Each result below comes from a run on this Mac, with main at ba0a233 on Core 3.20.0 where it matters.

P1, mid-month years. I reproduced all three behaviours, and they differ in where they come from.

  • A situation dict with wages for year:2026-03-31 stores them under year:2026-03 on 3.38.0. On 3.20.0 the build raised, as it did for any key with a colon.
  • A fresh calculation for year:2026-03-31 raises on 3.38.0. On 3.20.0 it gave $26,000 of Jobseeker Support with a reform that applies on 31 March 2026 alone.
  • After a calculation for year:2026-03-01, a calculation for year:2026-03-31 returns the 1 March result, $18,788.64, on both Cores. That alias predates the upgrade.

Each comes from Core keying a stored value by the period's string form, which drops the day. policyengine-core#526 tracks the fix, and the model has no simulation or builder of its own where it could catch these. test_core_refuses_a_year_that_starts_mid_month now checks the fresh calculation as well as set_input. Two strict xfail tests, which cite #526, check for a refusal on the situation-dict and cached routes. They fail while Core behaves this way, and once Core changes, strict xfail fails the suite so the marks come off. The changelog and the description now say which routes refuse and which still accept, and that a calculation for such a year now raises where 3.20.0 gave a result. In place of the four removed cases, the Jobseeker Support tests read the clause 1(d) rate from the parameter on 1 April 2022, 31 March 2026 and 1 April 2026. Both files now check that no rate is in force on 31 March 2022. The NZ Super tests already read each rate on 31 March and 1 April.

P1, the April situation-dict test. It now reads back $10,000 of employment_income for year:2025-04 before it checks 2022's tax. With Core's situation builder patched to drop that input, the old test passes and the new one fails, reading the $50,000 carried over from 2022.

P1, reform keys. I reproduced it. With the first rate set to 0 under the key "2027", tax on $50,000 is $6,020 for both 2027 and 2028 on 3.38.0, where 3.20.0 gave $7,658 for 2028. Under "2026-04-01.2027-03-31", the 2026-27 tax year, both Cores give $6,020 and $7,658. Two tests check both keys, and the bare-year test fails on 3.20.0. The changelog gives the range form for a reform meant for one tax year.

P1, the NaN counts. You are right. The NaN changes cover four files, and with a helper that stores nothing, 20 cases fail in seven test functions: 2 in ACC, 3 in the Accommodation Supplement, 1 in Jobseeker Support and 14 in Working for Families. My "eleven" counted one line per parametrized test. The description now says four files and 20 cases.

P1, NaN in a Boolean input. Confirmed on both Cores: receiving_nz_super set to NaN reads as true. The changelog, calculated.py, the test comments, the four amount docstrings and the description now say that Core refuses NaN in a float or int input. The description also says that a Boolean input still reads NaN as true.

P2, the disk test. It now asserts that the wages sit on disk and not in memory, and that age stays in memory, before it checks the tax. Its comment no longer cites the old recursion. On 3.20.0 it fails at the first of those checks, since the late memory limit leaves the wages in memory.

P2, nested and sibling branches. A new test gives the root $50,000 and a branch $60,000. A branch of that branch reads $60,000 and owes $10,220.50, and a sibling of the first branch reads the root's $50,000 and owes $7,658. On 3.20.0 the nested branch read the root's $50,000. In my probes a branch never read a sibling's input on either Core, so the description claims no change there.

P3, wording. The helper's docstring and the disk bullet now use direct wording.

Results that change. Of the other changes the review listed, I reproduced the carry-over (2027 tax from $0 to $7,658 with wages for 2022 and 2030), the nested branch, the bare-year reform key and the unknown earner status. The changelog and the description give each, and a test checks each. In my probes the sibling branch and the in-place parameter update behaved the same on both Cores, and I did not build the flat-file dataset case, so the description leaves those three out.

Round 2 follows.

Each xfail test now passes if Core either refuses a year that starts
mid-month or keeps it apart from the first of its month, so the marks
come off under policyengine-core#526's fix. The cached test sets the
31 March rate on a fresh system, since a Reform.from_dict system drops
the model's input carry-over. New tests cover an input stored under
another branch's name and a rate updated in place after a calculation.
The changelog states when Core 3.20.0 gave a nested branch the root's
input, names set_input and a fresh calculation as the routes that refuse
a year that starts mid-month, and says that 3.20.0 applied a bare date
key for that day alone.

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

Copy link
Copy Markdown
Contributor Author

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

25d4f8f corrects fae567a in three places, and round 2 reviews it.

  • Each xfail test now passes if Core either refuses a year that starts mid-month or keeps it apart from the first of its month, so the marks come off under either form of the policyengine-core#526 fix. With Core patched to refuse such a year in the situation builder and at the start of a calculation, both tests pass and strict xfail fails them. On 3.38.0 each fails at its last check.
  • The cached test sets the 31 March rate on a fresh system, since a system built through Reform.from_dict drops the model's input carry-over on both Cores.
  • My reply above said that an in-place parameter update behaved the same on both Cores. A later probe showed otherwise: on 3.20.0 a new simulation kept the rate it had already read. A new test covers it, and another covers an input stored under another branch's name, which 3.20.0 read when the simulation's own branch had none. The changelog and the description state both changes.

The suite passes on Core 3.38.0, 1,808 tests, with the two expected failures.

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

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

Round 2 review of 25d4f8f, run on this Mac as Subfleet lane job 20261202-230834-nzhub-rev-pe-nz-35-r2-lane: GPT-6.2 Sol at ultra effort. Verdict: REQUEST_CHANGES, with four new P1s, three P2s and one P3, and the first round's mid-month P1 still open for situation dicts.

It closes four of the five round-1 P1s (the April situation test, reform keys, the NaN counts and the NaN scope), the disk P2 and the P3.

  • P1, open from round 1: on 3.38.0, a situation dict's wages for year:2026-03-31 land under 1 March and can overwrite wages supplied for year:2026-03-01. Main refused that situation, so the upgrade turns an error into a silent wrong result.
  • P1: my earlier reply said the model has no hook where it could catch this. Core's builder calls TaxBenefitSystem.preprocess_situation before it buffers inputs, so NewZealandTaxBenefitSystem can refuse a year that starts mid-month there. A probe with that override refused both March fixtures and kept the April and 2022 inputs.
  • P1: the two xfail tests pass on false fixes. A Core that drops the March wage, or one that raises an unrelated error, turns them into strict XPASS.
  • P1: the description, the changelog and two test comments overstate which period keys 3.20.0 refused. A 15 January key loaded on both Cores.
  • P1: the description leaves out that a branch reads its nearest ancestor's input, and that an unknown earner status became AUTOMATIC only through set_input.
  • P2: the description and changelog leave out two flat-dataset changes: group inputs on person rows swap when ID order differs from row order, and period-suffixed role columns now work.
  • P2: the sibling test needs a case with no root wages, and the age check needs an input supplied after the memory limit.
  • P3: new comments use a contrast and passive clauses.

The reviewer ran test_core_version.py with 13 passed and 2 xfailed on 3.38.0 and 13 failed on 3.20.0, and the full suite with 1,808 passed and 2 xfailed on 3.38.0. I'll fix the P1s and P2s in this PR, and scoped rounds will review the commits that answer the P1s. A second round-2 review, a Codex cloud task sent on 1 December, has not returned yet; I'll answer anything new it raises in the same fix.

This branch has not been deployed

No deployments
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.

Upgrade policyengine-core past two 3.20.0 defects

1 participant