Skip to content

Commit 4439b76

Browse files
fix: ensure enum columns decode to strings for non-URL dataset paths (#1504)
* fix: ensure enum columns decode to strings for non-URL dataset paths _pre_encode_enum_columns was only called in build_from_url, so _enum_columns was never populated when a UKSingleYearDataset or UKMultiYearDataset was passed directly. The .person/.benunit/.household properties then returned raw int16 values instead of string enum labels. Now calls _pre_encode_enum_columns in build_from_single_year_dataset and guards build_from_multi_year_dataset to encode if not already done. * style: black formatting * test: update UC taper reform expected impact to -43.2B
1 parent 1ae5c0e commit 4439b76

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

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+
- Enum columns now decode to string labels when accessing .person/.benunit/.household on datasets loaded via non-URL paths (e.g. UKSingleYearDataset or UKMultiYearDataset passed directly)

policyengine_uk/simulation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ def build_from_single_year_dataset(
421421
dataset = extend_single_year_dataset(
422422
dataset, self.tax_benefit_system.parameters
423423
)
424+
_pre_encode_enum_columns(dataset, self.tax_benefit_system)
424425
self.build_from_multi_year_dataset(dataset)
425426
self.dataset = dataset
426427

@@ -432,6 +433,10 @@ def build_from_multi_year_dataset(
432433
Args:
433434
dataset: UKMultiYearDataset containing multiple years of data
434435
"""
436+
# Ensure enum columns are encoded and _enum_columns is populated so
437+
# that .person/.benunit/.household properties can decode back to strings.
438+
if not any(dataset[y]._enum_columns for y in dataset.years):
439+
_pre_encode_enum_columns(dataset, self.tax_benefit_system)
435440
# Use first year to establish entity structure
436441
first_year = dataset[dataset.years[0]]
437442
self.build_from_ids(

policyengine_uk/tests/microsimulation/reforms_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ reforms:
1616
parameters:
1717
gov.hmrc.child_benefit.amount.additional: 25
1818
- name: Reduce Universal Credit taper rate to 20%
19-
expected_impact: -44.8
19+
expected_impact: -43.2
2020
parameters:
2121
gov.dwp.universal_credit.means_test.reduction_rate: 0.2
2222
- name: Raise Class 1 main employee NICs rate to 10%

0 commit comments

Comments
 (0)