From 08d44606a38edf99aa9f0daeddeb825ce66a9935 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 15 Nov 2026 14:44:52 -0500 Subject: [PATCH 1/3] Let a parentless NZ reference person under 18 head a unit (B8 amendment) NZ's first real-data transport run refused the whole frame in unit construction: refuse_dependent_reference_person was true, so a household whose reference person was a parentless minor, or a parented minor living with another parentless child, aborted CREATE. On the pinned donor 9 of 57,240 households did this (0.0024% of household weight), each with an adult present. The NZ hub amends B8: the flag is false, so a reference person under 18 with no co-resident parent heads a unit, and a parentless child in a household whose reference person is a parented dependent child joins the unit that holds the reference person. Every frame that built before builds the same units. - benefit_unit_rule.json and docs/nz-benefit-unit-rule.md record the amendment, its counts, the non-statutory approximation, the Accommodation Supplement consequence and the refusal that remains. - benefit_unit_diagnostics gains parentless_reference_person_heads and younger_independent_teen_parents, so the receipt shows the new branch and the teen-parent counts partition parents under 18. - Tests: the refusal fixtures now expect the built units; the property tests draw minor reference persons, with an oracle for the caregiver-loop refusal; a strict-flag test keeps the shared strict branch covered. - Golden fingerprint and rule hash regenerated; changelog fragment. Co-Authored-By: Claude Opus 5.5 --- .../nz-b8-reference-teen-heads.changed.md | 14 + docs/nz-benefit-unit-rule.md | 32 +- .../microcosm/build/nz/benefit_unit_rule.json | 38 +- .../test_transport_dependent_children.py | 350 ++++++++++++++++-- .../test_transport_population_kernels.py | 2 + .../tests/golden/nz_country_spec.json | 4 +- .../src/microcosm/frame/unit_construction.py | 20 +- 7 files changed, 411 insertions(+), 49 deletions(-) create mode 100644 changelog.d/nz-b8-reference-teen-heads.changed.md diff --git a/changelog.d/nz-b8-reference-teen-heads.changed.md b/changelog.d/nz-b8-reference-teen-heads.changed.md new file mode 100644 index 0000000000..b51acadb22 --- /dev/null +++ b/changelog.d/nz-b8-reference-teen-heads.changed.md @@ -0,0 +1,14 @@ +Amend New Zealand's benefit-unit rule (G8 method addendum B8, 2026-11-15) so +CREATE builds a household whose reference person is under 18 with no +co-resident parent, or whose reference person is a dependent child while +another child has no co-resident parent, instead of refusing the whole frame. +Such a reference person is no longer a dependent child: they head a unit, and +any other child in the household with no co-resident parent joins it. This +holds at any age under 18, including a parent under 16, and in a household of +minors only, which the rule refused before. Every frame that built under the +old rule builds the same units. By the NZ hub's count on the pinned donor, 9 of +57,240 households tripped the old refusal. The CREATE receipt's +unit-construction counts gain `parentless_reference_person_heads` and +`younger_independent_teen_parents`; with the second, the three teen-parent +counts partition parents under 18. The rule file's hash and NZ's composition +fingerprint change. diff --git a/docs/nz-benefit-unit-rule.md b/docs/nz-benefit-unit-rule.md index 241fd8639e..bef65a3588 100644 --- a/docs/nz-benefit-unit-rule.md +++ b/docs/nz-benefit-unit-rule.md @@ -1,6 +1,6 @@ # NZ benefit unit: the dependent-child rule -`packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json` declares how the NZ graph builds benefit units. This note records the statutory basis and the cases the NZ hub settled on 2026-10-12 (G8 method note B8, for package G8-u of #1183). Every number lives in the spec; the shared unit-construction code reads it. +`packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json` declares how the NZ graph builds benefit units. This note records the statutory basis, the cases the NZ hub settled on 2026-10-12 (G8 method note B8, for package G8-u of #1183), and the hub's amendment of B8 on 2026-11-15. Every number lives in the spec; the shared unit-construction code reads it. ## Statutory basis @@ -21,12 +21,32 @@ The statute defines who is a dependent child. It does not say how a microsimulat - **Teen parents.** A 16- or 17-year-old with a co-resident child of their own forms their own unit with that child. - The basis is that Young Parent Payment is a main benefit for parents of that age, and receiving a main benefit makes a 16- or 17-year-old financially independent (DLM6784504, limb d), so not a child. - The rule infers this from the co-resident child pointer before the receipt layer runs; receipt itself is not observed here. - - A parent under 16 stays a dependent child in their own parent's unit, and their child joins that same unit. + - A parent under 16 with a co-resident parent stays a dependent child in their own parent's unit, and their child joins that same unit. A parent under 16 with no co-resident parent is placed as a child with no co-resident parent (below); if they are the household's reference person, they head their own unit and their child joins it. - These branches decide whether the teen parent is a dependent child. When the child's two co-resident parents end up in separate units, the child follows the declared parent-1 placement. - **Two co-resident parents who are not partners.** The child joins parent 1's unit. -- **A child with no co-resident parent.** The child joins the unit of the household's reference person. Construction refuses the household if that reference person is themselves a dependent child. +- **A child with no co-resident parent.** The child joins the unit that holds the household's reference person. If the reference person is a dependent child with a co-resident parent, that is the unit their parent chain leads to, usually their parent's. A reference person under 18 with no co-resident parent isn't treated as a dependent child, even if no partner, hours or parenthood test makes them independent: they head their own unit, and any other child with no co-resident parent joins it. This is the hub's amendment of 2026-11-15 (below); before it, construction refused these households. - **Orphan's benefit and unsupported child's benefit.** The statute excludes these children from "dependent child", but the donor can't identify them, so they remain dependent children of the unit they join. +## Amendment of 2026-11-15 + +B8 said construction refuses a household whose reference person is a dependent child. On 2026-11-15 the NZ hub amended B8 and dropped that refusal: the spec now sets `refuse_dependent_reference_person: false` and records the amendment under `child_without_coresident_parent.amendments`. + +- **What the refusal covered.** The shared constructor refused the whole frame in two cases: + - (i) the reference person is under 18, has no co-resident parent and isn't independent by partner, hours or parenthood, so the constructor kept them dependent and treated them as their own parentless child; + - (ii) the reference person is a dependent child with a co-resident parent, and another child in the household has no co-resident parent. + + Case (ii) is the refusal B8 states. Case (i) was the constructor's reading of it. The amendment drops both. +- **Why.** The strict reading refused real donor households, and one such household aborts the whole frame. The first real-data NZ transport run stopped on it. Literal B8 would still refuse case (ii), and keeping only that refusal would need a change to the shared constructor. +- **How many.** On the pinned donor, measured with the CREATE kernel's own reader and this spec, 9 of 57,240 households tripped the refusal, 0.0024% of household weight: + - 6 in case (ii), each with a reference person aged 15 or 16 whose parent is present, and another child with no co-resident parent; + - 3 in case (i), each with a reference person aged 16 or 17 with no co-resident parent. + + All 9 have a member aged 18 or over; none is a household of minors only. Without them the strict rule builds the frame. +- **What happens to them now.** The whole frame builds. Each case (i) reference person heads a one-person unit. In each case (ii) household, the child with no co-resident parent joins the unit of the reference person's parent, which no minor heads. Of the frame's 378 unit heads aged 17 or under, these 3 are the only ones heading a unit this way; the rest are partnered, independent teen parents or independent by hours. +- **Effect on the Accommodation Supplement.** A minor who heads a unit this way reads as a sole parent if the unit also holds another child with no co-resident parent, or their own child when they are under 16. The Accommodation Supplement's unit-based inputs (sole parent, has dependent children, two or more dependent children) and the rate bridge's sole-parent and child-count branches read that unit composition. The person-level inputs read parent pointers, so they don't count a sibling as that person's child. On this donor the 3 new heads are one-person units, so no minor reads as a sole parent through this branch. +- **What construction still refuses.** A dependent child whose caregivers never reach an adult is still refused, and that covers every household with no adult. A household of minors only now has an adult whenever its reference person has no co-resident parent, so it is refused only for unusual pointer data, such as a reference person who is a dependent child and whose parent 1 is under 16 with no co-resident parent or partner. No donor household reaches this refusal. +- **What the receipt counts.** The CREATE receipt gains two counts with this amendment: `parentless_reference_person_heads`, the minors who head a unit through this branch, and `younger_independent_teen_parents`, parents under 16 who aren't dependent because they head a unit this way or have a co-resident partner. With the second, the three teen-parent counts partition every parent under 18. + ## Disclosed approximations These are listed in the spec's `unobserved_statutory_limbs` and `financial_independence.approximation`. None is applied as a statutory exclusion. @@ -35,11 +55,13 @@ These are listed in the spec's `unobserved_statutory_limbs` and `financial_indep - Student allowance grants, analogous schemes, contractual full-time exceptions and main-benefit receipt aren't observed when units are built. - Single status is approximated by the co-resident partner pointer. A young person whose spouse or partner lives elsewhere is treated as single. MSD's section 8 determinations aren't observed. - Care, maintenance and financial dependency are represented by household and parent placement, not by observed support. +- A reference person under 18 with no co-resident parent heads their own unit (the amendment above). The statute makes no exception for a household reference person: the pointers name nobody whose dependent child they would be, and who cares for them isn't observed. ## Reported counts Unit construction reports, in the CREATE receipt: - 16- and 17-year-olds made independent by hours; -- teen parents in each branch; +- teen parents in each branch: independent at 16 or 17, not dependent under 16 (a partner, or a reference person with no co-resident parent heading their own unit), and dependent under 16; - households with non-partnered co-parents; -- children placed with the reference person. +- children placed with the reference person; +- reference persons under 18 with no co-resident parent who head their own unit (the amendment above). diff --git a/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json b/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json index 6476c0ea08..192cb1bd20 100644 --- a/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json +++ b/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json @@ -2,8 +2,8 @@ "version": 1, "country": "nz", "method_card_row": "MC7", - "description": "The New Zealand benefit unit (engine Family entity): an adult, their co-resident partner, and their dependent children; every other adult forms their own unit. An adult for unit construction is any person excluded from the declared dependent-child rule, including a financially independent young person or an independent teen parent. The unit id family.family_id and membership person.person_family_id are structural graph columns (microcosm.graph.executor._structural_columns); a non-structural node cannot own either (microcosm.graph.executor._validate_population_declaration). family.family_household_id is the ordinary family column linking each unit to its household. The shared transport CREATE kernel (G4/G5a; microcosm.build.transport.population_kernels.TransportCreateKernel) builds units from donor concept pointers under this spec. Family weights are inherited from the household through the Frame.", - "status": "settled by the NZ hub on 2026-10-12 under G8 method addendum B8 (MC7)", + "description": "The New Zealand benefit unit (engine Family entity): an adult, their co-resident partner, and their dependent children; every other adult forms their own unit. An adult for unit construction is any person excluded from the declared dependent-child rule, including a financially independent young person, an independent teen parent, or a household reference person below the age limit with no co-resident parent (child_without_coresident_parent, as amended on 2026-11-15). The unit id family.family_id and membership person.person_family_id are structural graph columns (microcosm.graph.executor._structural_columns); a non-structural node cannot own either (microcosm.graph.executor._validate_population_declaration). family.family_household_id is the ordinary family column linking each unit to its household. The shared transport CREATE kernel (G4/G5a; microcosm.build.transport.population_kernels.TransportCreateKernel) builds units from donor concept pointers under this spec. Family weights are inherited from the household through the Frame.", + "status": "settled by the NZ hub on 2026-10-12 under G8 method addendum B8 (MC7); B8 amended by the NZ hub on 2026-11-15 (child_without_coresident_parent.amendments)", "entity": "family", "engine_entity": "Family", "parent_entity": "household", @@ -48,7 +48,7 @@ "age_limit_years": 18, "age_limit_inclusive": false, "partnered_person_is_dependent_child": false, - "basis": "Social Security Act 2018, Schedule 2, as at 1 April 2026: child (LMS6902), dependent child (LMS7234), single (DLM6784713), and in a relationship (DLM6784537). The statutory definition requires a single person below the age limit and excludes financially independent persons in the declared young-person age range.", + "basis": "Social Security Act 2018, Schedule 2, as at 1 April 2026: child (LMS6902), dependent child (LMS7234), single (DLM6784713), and in a relationship (DLM6784537). The statutory definition requires a single person below the age limit and excludes financially independent persons in the declared young-person age range. A household reference person below the age limit with no co-resident parent is also excluded (child_without_coresident_parent); that exclusion is a modelling approximation, not a statutory one (unobserved_statutory_limbs).", "financial_independence": { "min_age": 16, "min_usual_weekly_hours": 30, @@ -63,16 +63,28 @@ }, "child_without_coresident_parent": { "central": "household_reference_person_unit", - "refuse_dependent_reference_person": true, - "status": "settled by the NZ hub on 2026-10-12, G8 method addendum B8", - "rule": "A dependent child with no co-resident parent joins the household reference person's unit. Refuse if the reference person is themselves a dependent child." + "refuse_dependent_reference_person": false, + "status": "settled by the NZ hub on 2026-10-12, G8 method addendum B8; amended by the NZ hub on 2026-11-15 (amendments)", + "rule": "A dependent child with no co-resident parent joins the unit that holds the household reference person. A household reference person below age_limit_years with no co-resident parent is not a dependent child, even when no other declared test makes them independent: they head their own unit, and their own co-resident children and every dependent child in the household with no co-resident parent join it. When the reference person is a dependent child with a co-resident parent, a dependent child with no co-resident parent follows the reference person's caregiver chain into the unit that holds the reference person: their parent's unit, or the unit further up the parent chain when that parent is also dependent. No placement is refused because the reference person is below the age limit; the caregiver refusal in refusals still applies.", + "amendments": [ + { + "date": "2026-11-15", + "by": "the NZ hub", + "amends": "G8 method addendum B8, settled 2026-10-12", + "change": "refuse_dependent_reference_person changed from true to false. With true, the shared constructor refused the whole frame in two cases: (i) the reference person is below the age limit, has no co-resident parent and is not otherwise independent, so the constructor kept them dependent and treated them as their own child with no co-resident parent; (ii) the reference person is a dependent child with a co-resident parent, and the household holds another dependent child with no co-resident parent. Case (ii) is the refusal B8 states; case (i) was the constructor's reading of it. This amendment drops both refusals.", + "reason": "The strict reading refused real donor households. The check runs over the whole frame, so one such household aborted the frame build, and the first real-data NZ transport run stopped on it. Literal B8 would still refuse case (ii), and the declaration has no setting that keeps case (ii) while dropping case (i); that would need a change to the shared constructor.", + "measured": "Measured on the pinned donor with the CREATE kernel's own reader and this declaration: 9 of 57,240 households, 0.0024% of household weight, tripped the refusal. 6 are case (ii): a reference person aged 15 or 16 with a parent present, and another child with no co-resident parent. 3 are case (i): a reference person aged 16 or 17 with no co-resident parent. Each of the 9 has a member aged 18 or over; none is a household of minors only. Without these 9 households the strict rule builds the frame. With this amendment the whole frame builds: each case (i) reference person heads a one-person unit, and in each case (ii) household the child with no co-resident parent joins the unit of the reference person's parent, which no minor heads. Of the frame's 378 unit heads aged 17 or under, these 3 are the only ones heading a unit through this branch; the others are adults under the partner, teen-parent or hours tests.", + "accommodation_supplement": "A minor who heads a unit through this branch reads as a sole parent when the unit also holds a dependent child: their own child when they are below parent_independence_min_age, or another child with no co-resident parent. family.is_sole_parent and family.n_dependent_children, the Accommodation Supplement inputs accommodation_supplement_sole_parent, accommodation_supplement_has_dependent_children and accommodation_supplement_has_two_or_more_dependent_children (unit_composition transforms in concept_mapping.json), and the rate bridge (as_rate_bridge.json) read that composition. The person-level inputs read parent pointers, so they count no sibling as that person's child. On the pinned donor the 3 new heads are one-person units, so no Accommodation Supplement input reads a minor as a sole parent through this branch. In case (ii) the unit of the reference person's parent holds one more dependent child.", + "receipt": "The CREATE receipt (microcosm.frame.unit_construction.benefit_unit_diagnostics) counts the persons below age_limit_years who head a unit through this branch as parentless_reference_person_heads, and counts a parent below parent_independence_min_age who heads a unit this way, or who has a co-resident partner, as younger_independent_teen_parents, so the three teen-parent counts partition the parents below age_limit_years (unit_construction_diagnostics)." + } + ] }, "refusals": [ "a unit whose members span two households", "a parent or partner pointer to a person outside the household", "an asymmetric partner pointer", "a dependent child in a household with no adult", - "placement of a child without a co-resident parent with a reference person who is themselves a dependent child" + "a dependent child whose caregivers never reach an adult (parent 1, or the household reference person for a child with no co-resident parent, followed through dependent caregivers), as when a reference person who is a dependent child has a parent 1 below parent_independence_min_age with no co-resident parent or partner" ], "open_cases": [], "invariants": [ @@ -95,7 +107,7 @@ } }, "settled_date": "2026-10-12", - "settlement_basis": "docs/nz-benefit-unit-rule.md (the NZ hub's G8 method note B8, settled 2026-10-12)", + "settlement_basis": "docs/nz-benefit-unit-rule.md (the NZ hub's G8 method note B8, settled 2026-10-12 and amended 2026-11-15)", "statutory_source": { "title": "Social Security Act 2018", "schedule": 2, @@ -119,7 +131,7 @@ }, "teen_parent": { "at_or_above_parent_independence_min_age": "A person below age_limit_years with a co-resident child of their own forms their own unit with that child once at or above parent_independence_min_age.", - "below_parent_independence_min_age": "A younger parent remains dependent under the other declared tests in their own parent's unit; their child joins that same unit. If the younger parent has no co-resident parent, the declared reference-person placement applies.", + "below_parent_independence_min_age": "The parent rule does not make a younger parent independent; the other declared tests decide. With a co-resident parent they remain dependent in their own parent's unit, and their child joins that same unit. Without one, the declared reference-person placement applies: they join the unit that holds the household reference person, or, when they are the reference person, they head their own unit and their child joins it (child_without_coresident_parent, as amended on 2026-11-15).", "basis": "Settled by the NZ hub on 2026-10-12, G8 method addendum B8. Young Parent Payment is a main benefit; Schedule 2 financially independent (DLM6784504, limb d) excludes its recipient from child. Unit construction infers the older teen-parent exclusion from the co-resident parent pointer before the receipt layer runs; receipt is not observed or assigned by this rule.", "placement_of_the_child": "These branches decide whether the teen parent is a dependent child. When the child's two co-resident parents end up in separate units, the child follows the declared parent-1 placement (split_parents)." }, @@ -156,13 +168,19 @@ { "definition": "single (DLM6784713) and in a relationship (DLM6784537), as used in child (LMS6902); section 8 (DLM6783126)", "omission": "Statutory single status is approximated by the co-resident partner pointer (partner_person_id). A married, civil-union or de facto young person whose spouse or partner does not live in the household is treated as single and can be placed as a dependent child. Legal marital status is not recovered by the donor decoder, and MSD determinations under section 8 that a person is or is not single are not observable; neither is applied." + }, + { + "definition": "child (LMS6902) and dependent child (LMS7234), for a household reference person below the age limit with no co-resident parent", + "omission": "Unit construction does not treat this person as a dependent child: they head their own unit, and their own co-resident children and any dependent child in the household with no co-resident parent join it (child_without_coresident_parent, amended by the NZ hub on 2026-11-15). This is a modelling approximation, not a statutory exclusion. The Act makes no exception for a household reference person; the pointers name no co-resident person whose dependent child they could be, and who has primary responsibility for them is not observed. It applies at any age below age_limit_years, so it can make a person under 16 the head of a unit." } ], "unit_construction_diagnostics": { "hours_independent_children": "Count of otherwise dependent candidates at or above financial_independence.min_age and below age_limit_years excluded by min_usual_weekly_hours.", "independent_teen_parents": "Count of persons below age_limit_years with a co-resident child, at or above parent_independence_min_age, excluded from dependency by the parent rule.", + "younger_independent_teen_parents": "Count of persons with a co-resident child, below parent_independence_min_age, who are not dependent children because another branch applies: a co-resident partner, or heading their own unit as a parentless household reference person. With independent_teen_parents and dependent_teen_parents it partitions the persons below age_limit_years who have a co-resident child.", "dependent_teen_parents": "Count of persons with a co-resident child below parent_independence_min_age who remain dependent under the declared rules.", "non_partnered_coparent_households": "Count of distinct households containing a dependent child with two co-resident parents who are not partners; count a household once even when several children qualify.", - "children_with_reference_person": "Count of dependent children with no co-resident parent placed in the household reference person's unit." + "children_with_reference_person": "Count of dependent children with no co-resident parent placed in the household reference person's unit.", + "parentless_reference_person_heads": "Count of household reference persons below age_limit_years with no co-resident parent whom neither a partner nor the hours or parent rules exclude from dependency; each heads their own unit because refuse_dependent_reference_person is false." } } diff --git a/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py b/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py index 38901ac917..a8b3cee0b4 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py @@ -7,7 +7,7 @@ import numpy as np import pandas as pd import pytest -from hypothesis import given, settings +from hypothesis import assume, given, settings from hypothesis import strategies as st from microcosm.frame import EntitySchema, Frame, WeightKind, Weights @@ -30,9 +30,11 @@ _DIAGNOSTIC_KEYS = ( "hours_independent_children", "independent_teen_parents", + "younger_independent_teen_parents", "dependent_teen_parents", "non_partnered_coparent_households", "children_with_reference_person", + "parentless_reference_person_heads", ) _PROPERTY = settings(max_examples=100, deadline=None) @@ -81,12 +83,16 @@ def _assert_units( diagnostics: dict[str, int], *, rule: BenefitUnitRule | None = None, + reference: int = 1, + roles: list[str] | None = None, ) -> None: - person, household = _household(rows) + person, household = _household(rows, reference=reference) rule = _rule() if rule is None else rule family, membership = build_benefit_units(person, household, rule) assert membership.tolist() == expected assert family[rule.id_column].tolist() == sorted(set(expected)) + if roles is not None: + assert benefit_unit_roles(person, family, membership, rule).tolist() == roles assert benefit_unit_diagnostics(person, household, family, membership, rule) == ( diagnostics ) @@ -199,37 +205,234 @@ def test_child_without_parent_joins_grandparent_reference_person() -> None: ) -def test_dependent_reference_person_is_refused() -> None: - person, household = _household( +def test_parentless_child_joins_a_dependent_reference_persons_unit() -> None: + # Amended B8: the 12-year-old reference person has a co-resident parent, so + # they stay a dependent child in that parent's unit. The parentless + # 8-year-old follows the reference person into the same unit. + _assert_units( [ {"person_id": 1, "age": 40}, {"person_id": 2, "age": 12, "parent_1_person_id": 1}, {"person_id": 3, "age": 8}, ], + [1, 1, 1], + _counts(children_with_reference_person=1), reference=2, + roles=["head", "dependent_child", "dependent_child"], ) - with pytest.raises(ValueError, match="reference person.*dependent child"): - build_benefit_units(person, household, _rule()) @pytest.mark.parametrize( - "other_person", + ("other_person", "diagnostics"), [ - pytest.param({"person_id": 2, "age": 10}, id="parentless-child"), + pytest.param( + {"person_id": 2, "age": 10}, + _counts( + children_with_reference_person=1, + parentless_reference_person_heads=1, + ), + id="parentless-child", + ), pytest.param( {"person_id": 2, "age": 0, "parent_1_person_id": 1}, - id="dependent-reference-parent-with-baby", + _counts( + younger_independent_teen_parents=1, + parentless_reference_person_heads=1, + ), + id="reference-parent-under-16-with-baby", ), ], ) -def test_household_with_dependent_reference_and_no_adult_is_refused( - other_person, +def test_parentless_reference_person_heads_a_household_of_minors( + other_person, diagnostics ) -> None: - person, household = _household([{"person_id": 1, "age": 15}, other_person]) - with pytest.raises(ValueError, match="reference person.*dependent child"): + # Amended B8: a reference person is never their own caregiver, so a + # 15-year-old reference person with no co-resident parent heads the unit. + # A parent under 16 who heads a unit counts as a younger independent teen + # parent. + _assert_units( + [{"person_id": 1, "age": 15}, other_person], + [1, 1], + diagnostics, + roles=["head", "dependent_child"], + ) + + +@pytest.mark.parametrize( + ("rows", "expected", "roles", "diagnostics"), + [ + pytest.param( + [ + {"person_id": 1, "age": 17}, + {"person_id": 2, "age": 45, "partner_person_id": 3}, + {"person_id": 3, "age": 43, "partner_person_id": 2}, + ], + [1, 2, 2], + ["head", "head", "partner"], + _counts(parentless_reference_person_heads=1), + id="parentless-17-year-old-with-adult-couple", + ), + pytest.param( + [{"person_id": 1, "age": 16}, {"person_id": 2, "age": 52}], + [1, 2], + ["head", "head"], + _counts(parentless_reference_person_heads=1), + id="parentless-16-year-old-with-adult", + ), + pytest.param( + [ + {"person_id": 1, "age": 15, "parent_1_person_id": 2}, + {"person_id": 2, "age": 44}, + {"person_id": 3, "age": 9}, + ], + [2, 2, 2], + ["dependent_child", "head", "dependent_child"], + _counts(children_with_reference_person=1), + id="15-year-old-with-parent-and-parentless-child", + ), + pytest.param( + [ + { + "person_id": 1, + "age": 16, + "parent_1_person_id": 2, + "parent_2_person_id": 3, + }, + {"person_id": 2, "age": 47, "partner_person_id": 3}, + {"person_id": 3, "age": 45, "partner_person_id": 2}, + {"person_id": 4, "age": 13}, + ], + [2, 2, 2, 2], + ["dependent_child", "head", "partner", "dependent_child"], + _counts(children_with_reference_person=1), + id="16-year-old-with-parents-and-parentless-child", + ), + pytest.param( + [ + {"person_id": 1, "age": 17}, + {"person_id": 2, "age": 15}, + {"person_id": 3, "age": 0, "parent_1_person_id": 2}, + ], + [1, 1, 1], + ["head", "dependent_child", "dependent_child"], + _counts( + dependent_teen_parents=1, + children_with_reference_person=1, + parentless_reference_person_heads=1, + ), + id="minors-only", + ), + ], +) +def test_teen_householder_shapes_from_the_donor_build( + rows, expected, roles, diagnostics +) -> None: + """The household shapes the first real NZ transport run refused, and one more. + + Person 1 is the reference person (the Census householder) in each. The + donor held parentless 16- and 17-year-old householders living with adults + who are not their partners; each now heads a one-person unit. It also held + 15- and 16-year-old householders living with a parent and with a child who + has no co-resident parent; that child now follows the householder into the + householder's parent's unit. No refused donor household held only minors; + that shape now builds too, headed by the parentless householder. + """ + _assert_units(rows, expected, diagnostics, roles=roles) + + +def test_reference_parent_chain_without_an_adult_is_refused() -> None: + # One refusal stays reachable with the flag off, from the shared caregiver + # loop rather than B8's reference check. The 12-year-old reference person's + # parent 1 is a parentless 15-year-old, whose caregiver is the reference + # person, so neither reaches an adult. The 40-year-old is in neither chain. + person, household = _household( + [ + {"person_id": 1, "age": 12, "parent_1_person_id": 2}, + {"person_id": 2, "age": 15}, + {"person_id": 3, "age": 40}, + ] + ) + with pytest.raises(ValueError, match="do not reach an adult"): build_benefit_units(person, household, _rule()) +def _strict_reference_rule() -> BenefitUnitRule: + """NZ's rule with the pre-amendment strict reference check turned back on.""" + spec = _spec() + spec["child_without_coresident_parent"]["refuse_dependent_reference_person"] = True + return BenefitUnitRule.from_spec(spec) + + +@pytest.mark.parametrize( + ("rows", "reference"), + [ + pytest.param( + [ + {"person_id": 1, "age": 40}, + {"person_id": 2, "age": 12, "parent_1_person_id": 1}, + {"person_id": 3, "age": 8}, + ], + 2, + id="parented-reference-with-parentless-child", + ), + pytest.param( + [{"person_id": 1, "age": 15}, {"person_id": 2, "age": 10}], + 1, + id="parentless-reference", + ), + ], +) +def test_strict_reference_flag_is_read_from_spec(rows, reference) -> None: + # NZ's amended rule builds both households (see the tests above). The + # shared strict branch, which no other test reaches, still refuses them + # when a spec turns the flag back on. + strict = _strict_reference_rule() + assert strict.refuse_dependent_reference_person is True + assert BenefitUnitRule.from_dict(strict.to_dict()) == strict + person, household = _household(rows, reference=reference) + with pytest.raises(ValueError, match="reference person.*dependent child"): + build_benefit_units(person, household, strict) + + +@pytest.mark.parametrize( + ("rows", "expected", "diagnostics"), + [ + pytest.param( + [ + {"person_id": 1, "age": 15}, + {"person_id": 2, "age": 0, "parent_1_person_id": 1}, + {"person_id": 3, "age": 50}, + ], + [1, 1, 3], + _counts( + younger_independent_teen_parents=1, + parentless_reference_person_heads=1, + ), + id="parentless-reference-parent-under-16", + ), + pytest.param( + [ + {"person_id": 1, "age": 40}, + {"person_id": 2, "age": 15, "partner_person_id": 3}, + {"person_id": 3, "age": 16, "partner_person_id": 2}, + {"person_id": 4, "age": 0, "parent_1_person_id": 2}, + ], + [1, 3, 3, 3], + _counts(younger_independent_teen_parents=1), + id="partnered-parent-under-16", + ), + ], +) +def test_parents_under_16_who_are_not_dependent_are_counted( + rows, expected, diagnostics +) -> None: + # Person 1 is the reference person. Counts are by hand: a parent under 16 + # who is not dependent, as a parentless reference person or a partner, is + # counted below the parent-independence age, so the three teen-parent + # counts partition parents under 18. + _assert_units(rows, expected, diagnostics) + + def test_country_spec_cannot_silently_use_an_inclusive_age_limit() -> None: spec = _spec() spec["dependent_child"]["age_limit_inclusive"] = True @@ -322,27 +525,87 @@ def test_declared_rule_round_trips_without_losing_settled_cases() -> None: assert restored == rule assert restored.dependent_child.max_age == 17 assert restored.dependent_child.parent_independence_min_age == 16 - assert restored.refuse_dependent_reference_person is True + assert restored.refuse_dependent_reference_person is False assert restored.dependent_child.financial_independence is not None assert restored.dependent_child.financial_independence.min_age == 16 assert restored.dependent_child.financial_independence.min_usual_weekly_hours == 30 @st.composite -def _households_with_adult_reference(draw) -> dict[str, pd.DataFrame]: +def _households_with_any_reference_age(draw) -> dict[str, pd.DataFrame]: tables = draw(concept_frames(max_households=5, max_members=7, min_id=-(10**6))) - references = tables["household"]["reference_person_id"] - # The refusal fixture checks dependent reference people. These generated - # frames have an observable adult caregiver, so all must construct units. - tables["person"].loc[tables["person"]["person_id"].isin(references), "age"] = draw( - st.integers(18, 130) - ) + person = tables["person"] + # Each reference person's age is drawn from 0 to 17 or from 18 to 130, so + # dependent-age reference people, with and without a co-resident parent, + # are drawn often. concept_frames draws ages independently of parent rank. + for reference in tables["household"]["reference_person_id"]: + person.loc[person["person_id"].eq(reference), "age"] = draw( + st.integers(0, 17) | st.integers(18, 130) + ) return tables +def _households_without_an_adult_caregiver( + person: pd.DataFrame, household: pd.DataFrame +) -> pd.Series: + """Households whose reference person's parent chain never reaches an adult. + + This restates amended B8 apart from unit_construction. A candidate child is + 17 or under, has no co-resident partner, is not a parent aged 16 or over and + does not work 30 hours a week at 16 or over. A candidate with a co-resident + parent joins parent 1's unit; a parentless candidate who is not the + reference person joins the reference person's unit. If a candidate + reference person's parent 1 is a candidate, and so is each parent 1 above, + the topmost has no co-resident parent and joins the reference person, so + the chain never reaches an adult. + """ + parents = set(person["parent_1_person_id"].dropna()) | set( + person["parent_2_person_id"].dropna() + ) + candidate = ( + person["age"].le(17) + & person["partner_person_id"].isna() + & ~(person["person_id"].isin(parents) & person["age"].ge(16)) + & ~(person["age"].ge(16) & person["usual_weekly_hours"].ge(30)) + ) + is_candidate = dict(zip(person["person_id"], candidate, strict=True)) + parent_1 = dict(zip(person["person_id"], person["parent_1_person_id"], strict=True)) + + def without_adult(reference: int) -> bool: + current = reference + while is_candidate[current] and not pd.isna(parent_1[current]): + current = parent_1[current] + return current != reference and is_candidate[current] + + return pd.Series( + [without_adult(item) for item in household["reference_person_id"]], + index=household.index, + dtype=bool, + ) + + +def _buildable_households( + person: pd.DataFrame, household: pd.DataFrame +) -> tuple[pd.DataFrame, pd.DataFrame]: + """Check the caregiver-loop refusal, then return the households that must build. + + One household whose reference chain reaches no adult refuses the whole + frame; every other household must still build. + """ + stuck = _households_without_an_adult_caregiver(person, household) + if stuck.any(): + with pytest.raises(ValueError, match="do not reach an adult"): + build_benefit_units(person, household, _rule()) + dropped = household.loc[stuck, "household_id"] + person = person.loc[~person["person_household_id"].isin(dropped)] + household = household.loc[~stuck] + assume(not household.empty) + return person.reset_index(drop=True), household.reset_index(drop=True) + + @_PROPERTY @given( - tables=_households_with_adult_reference(), + tables=_households_with_any_reference_age(), weights=st.lists( st.floats(min_value=0.001, max_value=1e6, allow_nan=False), min_size=5, @@ -350,14 +613,15 @@ def _households_with_adult_reference(draw) -> dict[str, pd.DataFrame]: ), ) def test_declared_nz_invariants_hold_for_random_households(tables, weights) -> None: - person, household = tables["person"], tables["household"] + person, household = _buildable_households(tables["person"], tables["household"]) rule = _rule() family, membership = build_benefit_units(person, household, rule) roles = benefit_unit_roles(person, family, membership, rule) unit_of = pd.Series(membership.to_numpy(), index=person["person_id"]) # Every person appears once, every constructed unit has members, and every - # unit has a head adult. An independent teen parent is an adult in this rule. + # unit has a head adult. An independent teen parent is an adult in this + # rule, and so is a reference person with no co-resident parent. assert membership.index.equals(person.index) assert membership.notna().all() assert membership.isin(family[rule.id_column]).all() @@ -380,11 +644,16 @@ def test_declared_nz_invariants_hold_for_random_households(tables, weights) -> N person["parent_2_person_id"].dropna() ) independent_parent = person["person_id"].isin(parents) & person["age"].ge(16) - assert not (child & (independent_worker | independent_parent)).any() + # Amended B8: a reference person is never their own caregiver, so one with + # no co-resident parent heads a unit at any age. + parentless_reference = ( + person["person_id"].isin(household["reference_person_id"]) + & person["parent_1_person_id"].isna() + ) + excluded = independent_worker | independent_parent | parentless_reference + assert not (child & excluded).any() adult = ~child - assert (person["age"].ge(18) | partnered | independent_worker | independent_parent)[ - adult - ].all() + assert (person["age"].ge(18) | partnered | excluded)[adult].all() with_parent = child & person["parent_1_person_id"].notna() assert ( membership[with_parent].tolist() @@ -399,6 +668,27 @@ def test_declared_nz_invariants_hold_for_random_households(tables, weights) -> N ).tolist() ) + # The teen-parent counts partition co-resident parents under 18, and the + # reference heads are the parentless reference persons under 18 whom no + # partner, hours or parent rule takes out of dependency. + diagnostics = benefit_unit_diagnostics(person, household, family, membership, rule) + young_parent = person["person_id"].isin(parents) & person["age"].lt(18) + assert int(young_parent.sum()) == ( + diagnostics["independent_teen_parents"] + + diagnostics["younger_independent_teen_parents"] + + diagnostics["dependent_teen_parents"] + ) + reference_teen = ( + person["person_id"].isin(household["reference_person_id"]) + & person["age"].lt(18) + & ~partnered + & ~independent_worker + & ~independent_parent + & person["parent_1_person_id"].isna() + ) + assert heads[reference_teen].all() + assert diagnostics["parentless_reference_person_heads"] == int(reference_teen.sum()) + unit_household = family.set_index(rule.id_column)[rule.household_column] assert ( unit_household.reindex(membership).tolist() @@ -433,11 +723,11 @@ def test_declared_nz_invariants_hold_for_random_households(tables, weights) -> N @_PROPERTY -@given(tables=_households_with_adult_reference(), data=st.data()) +@given(tables=_households_with_any_reference_age(), data=st.data()) def test_units_and_diagnostics_are_independent_of_person_row_order( tables, data ) -> None: - person, household = tables["person"], tables["household"] + person, household = _buildable_households(tables["person"], tables["household"]) rule = _rule() family, membership = build_benefit_units(person, household, rule) order = data.draw(st.permutations(range(len(person)))) diff --git a/packages/microcosm-build/tests/engine_free/shared/test_transport_population_kernels.py b/packages/microcosm-build/tests/engine_free/shared/test_transport_population_kernels.py index 56fa0f1544..abfef39c73 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_transport_population_kernels.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_transport_population_kernels.py @@ -854,9 +854,11 @@ def edit_tables(tables): assert dict(result.receipt["unit_construction"]) == { "hours_independent_children": int(independent), "independent_teen_parents": 0, + "younger_independent_teen_parents": 0, "dependent_teen_parents": 0, "non_partnered_coparent_households": 0, "children_with_reference_person": 0, + "parentless_reference_person_heads": 0, } diff --git a/packages/microcosm-build/tests/golden/nz_country_spec.json b/packages/microcosm-build/tests/golden/nz_country_spec.json index 22e05780ec..95d3045a94 100644 --- a/packages/microcosm-build/tests/golden/nz_country_spec.json +++ b/packages/microcosm-build/tests/golden/nz_country_spec.json @@ -1,6 +1,6 @@ { "country": "nz", - "fingerprint": "e631a3cfa065675f5162fa7accf6aa3f5014aa9bac962ad3f8909c72c4d24099", + "fingerprint": "552fc601d3cca63ef5176e30e81f4138c1d3e19658e73a9cb2971ac6f759d5a4", "gate_ids": [ "calibration_per_family_fit", "demography_per_family_fit", @@ -46,7 +46,7 @@ "axiom_input_closure.json": "acd994081b81c21f7b8da4ba80648d92cfd7ddd849db8bfa1db98c2fa2fe3b2e", "axiom_rules_bindings.json": "5a83c1dd1778dd33e58b4b4064df4ad5e32239e2bd812e53f4b1aac2e3e64e7f", "benefit_gross_up.json": "5518e7ad23b4053d36df842a3335358f8ff89c494ed065e540eb83585d8c6137", - "benefit_unit_rule.json": "c84efba8353c770131256a8c17b82c7d98f738e6dd8ef217e19d30014cb14604", + "benefit_unit_rule.json": "038015451480c0cad23187e69311b031880f6054816b5c6192908746f63bed03", "calibration_bindings.json": "26983da893770a7ea915d9eee70c47f310654ffe0fdffcc0327ac5a34c01bf50", "calibration_settings.json": "56e4d1da8468245da6bd41daf263425cc65e4e9c9f11ff45eee459d3aed1989e", "chronicle_feed.json": "598f4f50c0e68e28e7824470e262815bae88344c2ab7248339034841054dbffc", diff --git a/packages/microcosm-frame/src/microcosm/frame/unit_construction.py b/packages/microcosm-frame/src/microcosm/frame/unit_construction.py index 1e25a19310..db85725da1 100644 --- a/packages/microcosm-frame/src/microcosm/frame/unit_construction.py +++ b/packages/microcosm-frame/src/microcosm/frame/unit_construction.py @@ -915,8 +915,12 @@ def benefit_unit_diagnostics( Employment counts persons excluded by the hours limb who otherwise qualify as candidate children. Parent counts partition parents under the - child age limit at the declared parent-independence age. Co-parent counts - distinct households; reference placements count dependent children. + child age limit three ways: not dependent at or above the declared + parent-independence age, not dependent below it (for example a partner or + a parentless reference person), and dependent. Co-parent counts distinct + households; reference placements count dependent children. Reference heads + count parentless candidate children who head their own unit because they + are their household's reference person. """ rows = _Pointers.read(person, household, rule) dependent = ( @@ -931,16 +935,28 @@ def benefit_unit_diagnostics( both = dependent & (rows.parent_1 >= 0) & (rows.parent_2 >= 0) first, second = rows.parent_1[both], rows.parent_2[both] nonpartners = rows.partner[first] != second + is_reference = rows.reference == np.arange(len(rows.ids)) + reference_head = ( + _candidate_children(rows, rule) + & ~_hours_independent(rows, rule) + & (rows.parent_1 < 0) + & is_reference + & ~dependent + ) return { "hours_independent_children": int( (_candidate_children(rows, rule) & _hours_independent(rows, rule)).sum() ), "independent_teen_parents": int(independent_parent.sum()), + "younger_independent_teen_parents": int( + (young_parent & ~dependent & ~independent_parent).sum() + ), "dependent_teen_parents": int((young_parent & dependent).sum()), "non_partnered_coparent_households": int( len(np.unique(rows.household_ids[both][nonpartners])) ), "children_with_reference_person": int((dependent & (rows.parent_1 < 0)).sum()), + "parentless_reference_person_heads": int(reference_head.sum()), } From cfdd3c2e64a3bd95819607a4396f917b94e64348 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 15 Nov 2026 17:14:18 -0500 Subject: [PATCH 2/3] Fix review round 1 findings and Belgium's wording notes on B8 Review round 1 (Subfleet job 20261115-144611-mc1628-r1, head 08d44606a): - P1: the changelog said every listed reference person heads a unit. A reference person with a co-resident parent stays dependent. The fragment now describes the two cases separately and notes that a household whose caregivers never reach an adult is still refused. - P1: the rule text said a reference head's own co-resident children join their unit. A child follows parent 1, who can be another adult. The passages now name the dependent children who name them as parent 1. - P2: parentless_reference_person_heads counted heads made by own-unit placement. It now counts none under that placement; a new test covers each placement with the strict flag on and off. Belgium's notes 1, 2 and 5 on 08d44606a: the diagnostics docstring, the teen-parent and reference-placement wording in the rule and its docs, and the reported-count bullet. The docs now say "dependent child" where they said "child". The rule bytes changed, so NZ's golden hash and composition fingerprint are regenerated. Co-Authored-By: Claude Opus 5.5 --- .../nz-b8-reference-teen-heads.changed.md | 29 ++++--- docs/nz-benefit-unit-rule.md | 6 +- .../microcosm/build/nz/benefit_unit_rule.json | 8 +- .../test_transport_dependent_children.py | 80 +++++++++++++++++++ .../tests/golden/nz_country_spec.json | 4 +- .../src/microcosm/frame/unit_construction.py | 10 ++- 6 files changed, 112 insertions(+), 25 deletions(-) diff --git a/changelog.d/nz-b8-reference-teen-heads.changed.md b/changelog.d/nz-b8-reference-teen-heads.changed.md index b51acadb22..24f575b71d 100644 --- a/changelog.d/nz-b8-reference-teen-heads.changed.md +++ b/changelog.d/nz-b8-reference-teen-heads.changed.md @@ -1,14 +1,17 @@ Amend New Zealand's benefit-unit rule (G8 method addendum B8, 2026-11-15) so -CREATE builds a household whose reference person is under 18 with no -co-resident parent, or whose reference person is a dependent child while -another child has no co-resident parent, instead of refusing the whole frame. -Such a reference person is no longer a dependent child: they head a unit, and -any other child in the household with no co-resident parent joins it. This -holds at any age under 18, including a parent under 16, and in a household of -minors only, which the rule refused before. Every frame that built under the -old rule builds the same units. By the NZ hub's count on the pinned donor, 9 of -57,240 households tripped the old refusal. The CREATE receipt's -unit-construction counts gain `parentless_reference_person_heads` and -`younger_independent_teen_parents`; with the second, the three teen-parent -counts partition parents under 18. The rule file's hash and NZ's composition -fingerprint change. +CREATE builds two kinds of household it refused before, instead of refusing +the whole frame. A reference person under 18 with no co-resident parent is no +longer a dependent child: they head a unit, and the dependent children who +name them as parent 1, and every other dependent child in the household with +no co-resident parent, join it. This holds at any age under 18, including a +parent under 16, and in a household of minors only. A reference person who is +a dependent child with a co-resident parent stays dependent, and another +dependent child with no co-resident parent now follows the reference person's +caregiver chain into the unit that holds them. A household where a dependent +child's caregivers never reach an adult (anyone who is not a dependent child) +is still refused. Every frame that built under the old rule builds the same +units. By the NZ hub's count on the pinned donor, 9 of 57,240 households +tripped the old refusal. The CREATE receipt's unit-construction counts gain +`parentless_reference_person_heads` and `younger_independent_teen_parents`; +with the second, the three teen-parent counts partition parents under 18. The +rule file's hash and NZ's composition fingerprint change. diff --git a/docs/nz-benefit-unit-rule.md b/docs/nz-benefit-unit-rule.md index bef65a3588..f13891fd33 100644 --- a/docs/nz-benefit-unit-rule.md +++ b/docs/nz-benefit-unit-rule.md @@ -21,10 +21,10 @@ The statute defines who is a dependent child. It does not say how a microsimulat - **Teen parents.** A 16- or 17-year-old with a co-resident child of their own forms their own unit with that child. - The basis is that Young Parent Payment is a main benefit for parents of that age, and receiving a main benefit makes a 16- or 17-year-old financially independent (DLM6784504, limb d), so not a child. - The rule infers this from the co-resident child pointer before the receipt layer runs; receipt itself is not observed here. - - A parent under 16 with a co-resident parent stays a dependent child in their own parent's unit, and their child joins that same unit. A parent under 16 with no co-resident parent is placed as a child with no co-resident parent (below); if they are the household's reference person, they head their own unit and their child joins it. + - A parent under 16 with a co-resident parent stays a dependent child in their own parent's unit, and their child joins that same unit. A parent under 16 with no co-resident parent is placed as a child with no co-resident parent (below); if they are the household's reference person, they head their own unit and a child who names them as parent 1 joins it. - These branches decide whether the teen parent is a dependent child. When the child's two co-resident parents end up in separate units, the child follows the declared parent-1 placement. - **Two co-resident parents who are not partners.** The child joins parent 1's unit. -- **A child with no co-resident parent.** The child joins the unit that holds the household's reference person. If the reference person is a dependent child with a co-resident parent, that is the unit their parent chain leads to, usually their parent's. A reference person under 18 with no co-resident parent isn't treated as a dependent child, even if no partner, hours or parenthood test makes them independent: they head their own unit, and any other child with no co-resident parent joins it. This is the hub's amendment of 2026-11-15 (below); before it, construction refused these households. +- **A child with no co-resident parent.** The child joins the unit that holds the household's reference person. If the reference person is a dependent child with a co-resident parent, that is the unit their parent chain leads to, usually their parent's. A reference person under 18 with no co-resident parent isn't treated as a dependent child, even if no partner, hours or parenthood test makes them independent: they head their own unit, and any other dependent child with no co-resident parent joins it. This is the hub's amendment of 2026-11-15 (below); before it, construction refused these households. - **Orphan's benefit and unsupported child's benefit.** The statute excludes these children from "dependent child", but the donor can't identify them, so they remain dependent children of the unit they join. ## Amendment of 2026-11-15 @@ -64,4 +64,4 @@ Unit construction reports, in the CREATE receipt: - teen parents in each branch: independent at 16 or 17, not dependent under 16 (a partner, or a reference person with no co-resident parent heading their own unit), and dependent under 16; - households with non-partnered co-parents; - children placed with the reference person; -- reference persons under 18 with no co-resident parent who head their own unit (the amendment above). +- reference persons under 18 with no co-resident parent who head their own unit only as the reference person, not as a partner, an independent teen parent or a worker independent by hours (the amendment above). diff --git a/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json b/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json index 192cb1bd20..e32cd8e5e0 100644 --- a/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json +++ b/packages/microcosm-build/src/microcosm/build/nz/benefit_unit_rule.json @@ -65,7 +65,7 @@ "central": "household_reference_person_unit", "refuse_dependent_reference_person": false, "status": "settled by the NZ hub on 2026-10-12, G8 method addendum B8; amended by the NZ hub on 2026-11-15 (amendments)", - "rule": "A dependent child with no co-resident parent joins the unit that holds the household reference person. A household reference person below age_limit_years with no co-resident parent is not a dependent child, even when no other declared test makes them independent: they head their own unit, and their own co-resident children and every dependent child in the household with no co-resident parent join it. When the reference person is a dependent child with a co-resident parent, a dependent child with no co-resident parent follows the reference person's caregiver chain into the unit that holds the reference person: their parent's unit, or the unit further up the parent chain when that parent is also dependent. No placement is refused because the reference person is below the age limit; the caregiver refusal in refusals still applies.", + "rule": "A dependent child with no co-resident parent joins the unit that holds the household reference person. A household reference person below age_limit_years with no co-resident parent is not a dependent child, even when no other declared test makes them independent: they head their own unit, and the dependent children who name them as parent 1, and every dependent child in the household with no co-resident parent, join it. When the reference person is a dependent child with a co-resident parent, a dependent child with no co-resident parent follows the reference person's caregiver chain into the unit that holds the reference person: their parent's unit, or the unit further up the parent chain when that parent is also dependent. No placement is refused because the reference person is below the age limit; the caregiver refusal in refusals still applies.", "amendments": [ { "date": "2026-11-15", @@ -131,7 +131,7 @@ }, "teen_parent": { "at_or_above_parent_independence_min_age": "A person below age_limit_years with a co-resident child of their own forms their own unit with that child once at or above parent_independence_min_age.", - "below_parent_independence_min_age": "The parent rule does not make a younger parent independent; the other declared tests decide. With a co-resident parent they remain dependent in their own parent's unit, and their child joins that same unit. Without one, the declared reference-person placement applies: they join the unit that holds the household reference person, or, when they are the reference person, they head their own unit and their child joins it (child_without_coresident_parent, as amended on 2026-11-15).", + "below_parent_independence_min_age": "The parent rule does not make a younger parent independent; the other declared tests decide. With a co-resident parent they remain dependent in their own parent's unit, and their child joins that same unit. Without one, the declared reference-person placement applies: they join the unit that holds the household reference person, or, when they are the reference person, they head their own unit and a child who names them as parent 1 joins it (child_without_coresident_parent, as amended on 2026-11-15).", "basis": "Settled by the NZ hub on 2026-10-12, G8 method addendum B8. Young Parent Payment is a main benefit; Schedule 2 financially independent (DLM6784504, limb d) excludes its recipient from child. Unit construction infers the older teen-parent exclusion from the co-resident parent pointer before the receipt layer runs; receipt is not observed or assigned by this rule.", "placement_of_the_child": "These branches decide whether the teen parent is a dependent child. When the child's two co-resident parents end up in separate units, the child follows the declared parent-1 placement (split_parents)." }, @@ -171,7 +171,7 @@ }, { "definition": "child (LMS6902) and dependent child (LMS7234), for a household reference person below the age limit with no co-resident parent", - "omission": "Unit construction does not treat this person as a dependent child: they head their own unit, and their own co-resident children and any dependent child in the household with no co-resident parent join it (child_without_coresident_parent, amended by the NZ hub on 2026-11-15). This is a modelling approximation, not a statutory exclusion. The Act makes no exception for a household reference person; the pointers name no co-resident person whose dependent child they could be, and who has primary responsibility for them is not observed. It applies at any age below age_limit_years, so it can make a person under 16 the head of a unit." + "omission": "Unit construction does not treat this person as a dependent child: they head their own unit, and the dependent children who name them as parent 1, and any dependent child in the household with no co-resident parent, join it (child_without_coresident_parent, amended by the NZ hub on 2026-11-15). This is a modelling approximation, not a statutory exclusion. The Act makes no exception for a household reference person; the pointers name no co-resident person whose dependent child they could be, and who has primary responsibility for them is not observed. It applies at any age below age_limit_years, so it can make a person under 16 the head of a unit." } ], "unit_construction_diagnostics": { @@ -180,7 +180,7 @@ "younger_independent_teen_parents": "Count of persons with a co-resident child, below parent_independence_min_age, who are not dependent children because another branch applies: a co-resident partner, or heading their own unit as a parentless household reference person. With independent_teen_parents and dependent_teen_parents it partitions the persons below age_limit_years who have a co-resident child.", "dependent_teen_parents": "Count of persons with a co-resident child below parent_independence_min_age who remain dependent under the declared rules.", "non_partnered_coparent_households": "Count of distinct households containing a dependent child with two co-resident parents who are not partners; count a household once even when several children qualify.", - "children_with_reference_person": "Count of dependent children with no co-resident parent placed in the household reference person's unit.", + "children_with_reference_person": "Count of dependent children with no co-resident parent placed in the unit that holds the household reference person.", "parentless_reference_person_heads": "Count of household reference persons below age_limit_years with no co-resident parent whom neither a partner nor the hours or parent rules exclude from dependency; each heads their own unit because refuse_dependent_reference_person is false." } } diff --git a/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py b/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py index a8b3cee0b4..a0193d6d68 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_transport_dependent_children.py @@ -3,6 +3,7 @@ from __future__ import annotations import json +from dataclasses import replace import numpy as np import pandas as pd @@ -14,6 +15,7 @@ from microcosm.frame.concept_mapping import UnitRole from microcosm.frame.unit_construction import ( BenefitUnitRule, + UnparentedChildPlacement, benefit_unit_diagnostics, benefit_unit_roles, build_benefit_units, @@ -394,6 +396,84 @@ def test_strict_reference_flag_is_read_from_spec(rows, reference) -> None: build_benefit_units(person, household, strict) +_PARENTLESS_PAIR = [{"person_id": 1, "age": 15}, {"person_id": 2, "age": 10}] +_LONE_REFERENCE = [{"person_id": 1, "age": 15}] + + +@pytest.mark.parametrize( + ("placement", "strict", "rows", "expected", "diagnostics"), + [ + pytest.param( + UnparentedChildPlacement.REFERENCE_PERSON_UNIT, + False, + _PARENTLESS_PAIR, + [1, 1], + _counts( + children_with_reference_person=1, + parentless_reference_person_heads=1, + ), + id="reference-unit", + ), + pytest.param( + UnparentedChildPlacement.REFERENCE_PERSON_UNIT, + True, + _PARENTLESS_PAIR, + None, + "reference person.*dependent child", + id="reference-unit-strict", + ), + pytest.param( + UnparentedChildPlacement.OWN_UNIT, + False, + _PARENTLESS_PAIR, + [1, 2], + _counts(), + id="own-unit", + ), + pytest.param( + UnparentedChildPlacement.OWN_UNIT, + True, + _PARENTLESS_PAIR, + [1, 2], + _counts(), + id="own-unit-strict", + ), + pytest.param( + UnparentedChildPlacement.REFUSE, + False, + _LONE_REFERENCE, + [1], + _counts(parentless_reference_person_heads=1), + id="refuse", + ), + pytest.param( + UnparentedChildPlacement.REFUSE, + True, + _LONE_REFERENCE, + None, + "refuses 1 candidate child", + id="refuse-strict", + ), + ], +) +def test_reference_heads_count_only_the_reference_branch( + placement, strict, rows, expected, diagnostics +) -> None: + # Person 1, aged 15 with no co-resident parent, is the reference person. + # Reference heads count them only when being the reference person is what + # makes them a head: own-unit placement heads every parentless candidate, + # and the strict flag refuses the frame before any count. + rule = replace( + _rule(), unparented_child=placement, refuse_dependent_reference_person=strict + ) + if expected is None: + person, household = _household(rows) + with pytest.raises(ValueError, match=diagnostics): + build_benefit_units(person, household, rule) + else: + _assert_units(rows, expected, diagnostics, rule=rule) + + @pytest.mark.parametrize( ("rows", "expected", "diagnostics"), [ diff --git a/packages/microcosm-build/tests/golden/nz_country_spec.json b/packages/microcosm-build/tests/golden/nz_country_spec.json index 95d3045a94..211f04bfb3 100644 --- a/packages/microcosm-build/tests/golden/nz_country_spec.json +++ b/packages/microcosm-build/tests/golden/nz_country_spec.json @@ -1,6 +1,6 @@ { "country": "nz", - "fingerprint": "552fc601d3cca63ef5176e30e81f4138c1d3e19658e73a9cb2971ac6f759d5a4", + "fingerprint": "8367a4578c093d50af51a4ece40b03e5cb814d09d8c05712c316cd3c29d2b435", "gate_ids": [ "calibration_per_family_fit", "demography_per_family_fit", @@ -46,7 +46,7 @@ "axiom_input_closure.json": "acd994081b81c21f7b8da4ba80648d92cfd7ddd849db8bfa1db98c2fa2fe3b2e", "axiom_rules_bindings.json": "5a83c1dd1778dd33e58b4b4064df4ad5e32239e2bd812e53f4b1aac2e3e64e7f", "benefit_gross_up.json": "5518e7ad23b4053d36df842a3335358f8ff89c494ed065e540eb83585d8c6137", - "benefit_unit_rule.json": "038015451480c0cad23187e69311b031880f6054816b5c6192908746f63bed03", + "benefit_unit_rule.json": "50f6379bdd6e307ed2c7325662366d5f71b88c48a09efaa45a05af14de3d08dc", "calibration_bindings.json": "26983da893770a7ea915d9eee70c47f310654ffe0fdffcc0327ac5a34c01bf50", "calibration_settings.json": "56e4d1da8468245da6bd41daf263425cc65e4e9c9f11ff45eee459d3aed1989e", "chronicle_feed.json": "598f4f50c0e68e28e7824470e262815bae88344c2ab7248339034841054dbffc", diff --git a/packages/microcosm-frame/src/microcosm/frame/unit_construction.py b/packages/microcosm-frame/src/microcosm/frame/unit_construction.py index db85725da1..8fa5eb3523 100644 --- a/packages/microcosm-frame/src/microcosm/frame/unit_construction.py +++ b/packages/microcosm-frame/src/microcosm/frame/unit_construction.py @@ -917,10 +917,13 @@ def benefit_unit_diagnostics( qualify as candidate children. Parent counts partition parents under the child age limit three ways: not dependent at or above the declared parent-independence age, not dependent below it (for example a partner or - a parentless reference person), and dependent. Co-parent counts distinct + a parentless reference person), and dependent; with no declared age, every + parent who is not dependent is in the first. Co-parent counts distinct households; reference placements count dependent children. Reference heads - count parentless candidate children who head their own unit because they - are their household's reference person. + count parentless candidate children who head their own unit only because + they are their household's reference person. Own-unit placement makes + every parentless candidate a head, so it counts none; the strict reference + flag refuses those frames before any count. """ rows = _Pointers.read(person, household, rule) dependent = ( @@ -942,6 +945,7 @@ def benefit_unit_diagnostics( & (rows.parent_1 < 0) & is_reference & ~dependent + & (rule.unparented_child is not UnparentedChildPlacement.OWN_UNIT) ) return { "hours_independent_children": int( From 1fec5b299f8a55dffca1a4a48deeaf2ecfcc4d2b Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 15 Nov 2026 17:17:28 -0500 Subject: [PATCH 3/3] Say which placements the strict flag refuses in the diagnostics docstring Under own-unit placement, strict frames build and count no reference head, so "refuses those frames" applies only to the other placements (Belgian port's optional note on cfdd3c2e6). Co-Authored-By: Claude Opus 5.5 --- .../microcosm-frame/src/microcosm/frame/unit_construction.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/microcosm-frame/src/microcosm/frame/unit_construction.py b/packages/microcosm-frame/src/microcosm/frame/unit_construction.py index 8fa5eb3523..461e532af8 100644 --- a/packages/microcosm-frame/src/microcosm/frame/unit_construction.py +++ b/packages/microcosm-frame/src/microcosm/frame/unit_construction.py @@ -922,8 +922,9 @@ def benefit_unit_diagnostics( households; reference placements count dependent children. Reference heads count parentless candidate children who head their own unit only because they are their household's reference person. Own-unit placement makes - every parentless candidate a head, so it counts none; the strict reference - flag refuses those frames before any count. + every parentless candidate a head, so it counts none; under the other + placements, the strict reference flag refuses those frames before any + count. """ rows = _Pointers.read(person, household, rule) dependent = (