Skip to content

Commit b7677d4

Browse files
Fix climate_action_incentive_category enum crash (#550)
* Fix climate_action_incentive_category enum crash select() with no default returns 0 (int) when no condition matches, which fails enum encoding. This happens for children in two-parent households who don't match any of the four conditions. Add default=OTHER_CHILD so unmatched persons get a valid enum value. This unblocks household_net_income and marginal_tax_rate calculations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add tests for climate_action_incentive_category fix - Test category assignment for two-parent household with child (the crash case) - Test single-parent household eldest child gets special category - Test single person gets HEAD - Integration test for two-parent and married-couple households Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add changelog entry for climate action category fix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8526612 commit b7677d4

4 files changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed climate_action_incentive_category enum crash that broke household_net_income and marginal_tax_rate for all household types.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
- name: Two-parent household with child — category defaults without crash
2+
period: 2026
3+
input:
4+
people:
5+
parent1:
6+
age: 35
7+
is_head: true
8+
is_spouse: false
9+
employment_income: 50_000
10+
parent2:
11+
age: 33
12+
is_head: false
13+
is_spouse: true
14+
child:
15+
age: 5
16+
is_head: false
17+
is_spouse: false
18+
households:
19+
household:
20+
members: [parent1, parent2, child]
21+
province_code: ONT
22+
is_married: true
23+
output:
24+
climate_action_incentive_category:
25+
- HEAD
26+
- SPOUSE
27+
- OTHER_CHILD
28+
29+
- name: Single parent household — eldest child gets special category
30+
period: 2026
31+
input:
32+
people:
33+
parent:
34+
age: 35
35+
is_head: true
36+
is_spouse: false
37+
employment_income: 45_000
38+
child1:
39+
age: 10
40+
is_head: false
41+
is_spouse: false
42+
is_dependant: true
43+
child2:
44+
age: 7
45+
is_head: false
46+
is_spouse: false
47+
is_dependant: true
48+
households:
49+
household:
50+
members: [parent, child1, child2]
51+
province_code: ONT
52+
is_married: false
53+
output:
54+
climate_action_incentive_category:
55+
- HEAD
56+
- ELDEST_CHILD_IN_SINGLE_PARENT_HOUSEHOLD
57+
- OTHER_CHILD
58+
59+
- name: Single person — head only
60+
period: 2026
61+
input:
62+
people:
63+
person:
64+
age: 40
65+
is_head: true
66+
is_spouse: false
67+
employment_income: 90_000
68+
households:
69+
household:
70+
members: [person]
71+
province_code: ONT
72+
output:
73+
climate_action_incentive_category:
74+
- HEAD
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
- name: Two-parent household with child — household_net_income does not crash
2+
period: 2026
3+
absolute_error_margin: 1
4+
input:
5+
people:
6+
parent1:
7+
age: 35
8+
is_head: true
9+
is_spouse: false
10+
employment_income: 50_000
11+
parent2:
12+
age: 33
13+
is_head: false
14+
is_spouse: true
15+
employment_income: 30_000
16+
child:
17+
age: 5
18+
is_head: false
19+
is_spouse: false
20+
households:
21+
household:
22+
members: [parent1, parent2, child]
23+
province_code: ONT
24+
is_married: true
25+
output:
26+
climate_action_incentive_category:
27+
- HEAD
28+
- SPOUSE
29+
- OTHER_CHILD
30+
31+
- name: Married couple no children — climate action does not crash
32+
period: 2026
33+
absolute_error_margin: 1
34+
input:
35+
people:
36+
head:
37+
age: 40
38+
is_head: true
39+
is_spouse: false
40+
employment_income: 90_000
41+
spouse:
42+
age: 38
43+
is_head: false
44+
is_spouse: true
45+
households:
46+
household:
47+
members: [head, spouse]
48+
province_code: ONT
49+
is_married: true
50+
output:
51+
climate_action_incentive_category:
52+
- HEAD
53+
- SPOUSE

policyengine_canada/variables/gov/cra/tax/income/credits/climate_action/climate_action_incentive_category.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ def formula(person, period, parameters):
4141
ClimateActionIncentiveCategory.ELDEST_CHILD_IN_SINGLE_PARENT_HOUSEHOLD,
4242
ClimateActionIncentiveCategory.OTHER_CHILD,
4343
],
44+
default=ClimateActionIncentiveCategory.OTHER_CHILD,
4445
)

0 commit comments

Comments
 (0)