Skip to content

Commit d4ff3b2

Browse files
committed
Change if to where
1 parent cf7f6e6 commit d4ff3b2

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare_benefits.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,21 @@ def formula(benunit, period, parameters):
4141
meets_age_condition & meets_income_condition & childcare_eligible
4242
)
4343

44-
# Determine the maximum eligible childcare cost for a single child
45-
max_amount = 0
44+
# Calculate maximum eligible childcare cost using vectorized operations
4645
child_mask = benunit.members("is_child", period)
47-
for member in benunit.members:
48-
disabled = benunit.members("is_disabled", period)[member]
49-
max_amount = where(
50-
child_mask[member],
46+
disabled = benunit.members("is_disabled", period)
47+
max_amount = where(
48+
child_mask,
49+
where(
50+
is_eligible,
5151
where(
52-
is_eligible,
53-
where(
54-
disabled,
55-
p.disabled_child.values,
56-
p.standard_child.values,
57-
),
58-
max_amount,
52+
disabled,
53+
p.disabled_child.values,
54+
p.standard_child.values,
5955
),
60-
max_amount,
61-
)
56+
0,
57+
),
58+
0,
59+
).max(axis=0)
6260

6361
return where(is_eligible, max_amount, 0)

0 commit comments

Comments
 (0)