Skip to content

Commit 4a12215

Browse files
authored
Merge pull request #266 from PolicyEngine/fix/region-values-comparison
fix: use region.values for Scotland comparisons in loss function
2 parents e3586a6 + a620a5d commit 4a12215

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

.github/workflows/pull_request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip
27-
pip install black==25.1.0
27+
pip install black
2828
- name: Check formatting
2929
run: black . -l 79 --check
3030
test:

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: patch
2+
changes:
3+
fixed:
4+
- Use region.values for Scotland comparisons in loss function to ensure consistent behavior with StringArray types

policyengine_uk_data/tests/test_scotland_uc_babies.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ def test_scotland_uc_households_child_under_1(baseline):
1818
Target: ~14,000 households (13,992 from Stat-Xplore November 2023)
1919
Source: DWP Stat-Xplore UC Households dataset
2020
"""
21-
region = baseline.calculate(
22-
"region", map_to="household", period=2025
23-
).values
21+
region = baseline.calculate("region", map_to="household", period=2025)
2422
uc = baseline.calculate("universal_credit", period=2025).values
2523
household_weight = baseline.calculate(
2624
"household_weight", map_to="household", period=2025
@@ -38,7 +36,7 @@ def test_scotland_uc_households_child_under_1(baseline):
3836
)
3937

4038
scotland_uc_child_under_1 = (
41-
(region == "SCOTLAND") & (uc > 0) & has_child_under_1
39+
(region.values == "SCOTLAND") & (uc > 0) & has_child_under_1
4240
)
4341
total = (household_weight * scotland_uc_child_under_1).sum()
4442

policyengine_uk_data/utils/loss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def pe_count(*variables):
267267
# Children under 16 in Scotland
268268
# Source: NRS mid-year population estimates
269269
# https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/population/population-estimates/mid-year-population-estimates
270-
scotland_children_under_16 = (region == "SCOTLAND") & (age < 16)
270+
scotland_children_under_16 = (region.values == "SCOTLAND") & (age < 16)
271271
df["ons/scotland_children_under_16"] = household_from_person(
272272
scotland_children_under_16
273273
)
@@ -276,7 +276,7 @@ def pe_count(*variables):
276276
# Source: NRS Vital Events - births registered in Scotland
277277
# https://www.nrscotland.gov.uk/publications/vital-events-reference-tables-2024/
278278
# ~46,000 births per year (45,763 in 2024)
279-
scotland_babies_under_1 = (region == "SCOTLAND") & (age < 1)
279+
scotland_babies_under_1 = (region.values == "SCOTLAND") & (age < 1)
280280
df["ons/scotland_babies_under_1"] = household_from_person(
281281
scotland_babies_under_1
282282
)

0 commit comments

Comments
 (0)