diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29bb..ae4337a7b 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: patch + changes: + fixed: + - Bug in handling downloads of UKMultiYearDataset from HuggingFace. \ No newline at end of file diff --git a/policyengine_uk/data/dataset_schema.py b/policyengine_uk/data/dataset_schema.py index a6cbd8cdf..9f6a04f2b 100644 --- a/policyengine_uk/data/dataset_schema.py +++ b/policyengine_uk/data/dataset_schema.py @@ -213,12 +213,11 @@ def validate_file_path(file_path: str): # Check if the file contains datasets for multiple years with h5py.File(file_path, "r") as f: - if not any(key.startswith("/person/") for key in f.keys()): - raise ValueError("No person dataset found in the file.") - if not any(key.startswith("/benunit/") for key in f.keys()): - raise ValueError("No benunit dataset found in the file.") - if not any(key.startswith("/household/") for key in f.keys()): - raise ValueError("No household dataset found in the file.") + for required_dataset in ["person", "benunit", "household"]: + if not any(f"{required_dataset}" in key for key in f.keys()): + raise ValueError( + f"Dataset '{required_dataset}' not found in the file: {file_path}" + ) def load(self): data = {} diff --git a/policyengine_uk/system.py b/policyengine_uk/system.py index 01385a546..ae2d9bcf8 100644 --- a/policyengine_uk/system.py +++ b/policyengine_uk/system.py @@ -202,9 +202,13 @@ def __init__(self, *args, dataset=ENHANCED_FRS, **kwargs): dataset = UKMultiYearDataset( file_path=dataset_file_path ) - except: + except Exception as e: pass - dataset = Dataset.from_file(dataset_file_path) + + if not isinstance( + dataset, (UKSingleYearDataset, UKMultiYearDataset) + ): + dataset = Dataset.from_file(dataset_file_path) super().__init__(*args, dataset=dataset, **kwargs) diff --git a/policyengine_uk/tests/microsimulation/reforms_config.yaml b/policyengine_uk/tests/microsimulation/reforms_config.yaml index b6be6b317..71ce38fb9 100644 --- a/policyengine_uk/tests/microsimulation/reforms_config.yaml +++ b/policyengine_uk/tests/microsimulation/reforms_config.yaml @@ -1,10 +1,10 @@ reforms: - name: Raise basic rate by 1pp - expected_impact: 7.6 + expected_impact: 7.5 parameters: gov.hmrc.income_tax.rates.uk[0].rate: 0.21 - name: Raise higher rate by 1pp - expected_impact: 4.8 + expected_impact: 4.7 parameters: gov.hmrc.income_tax.rates.uk[1].rate: 0.42 - name: Raise personal allowance by ~800GBP/year @@ -16,7 +16,7 @@ reforms: parameters: gov.hmrc.child_benefit.amount.additional: 25 - name: Reduce Universal Credit taper rate to 20% - expected_impact: -36.5 + expected_impact: -36.4 parameters: gov.dwp.universal_credit.means_test.reduction_rate: 0.2 - name: Raise Class 1 main employee NICs rate to 10% @@ -24,10 +24,10 @@ reforms: parameters: gov.hmrc.national_insurance.class_1.rates.employee.main: 0.1 - name: Raise VAT standard rate by 2pp - expected_impact: 18.8 + expected_impact: 18.9 parameters: gov.hmrc.vat.standard_rate: 0.22 - name: Raise additional rate by 3pp - expected_impact: 5.5 + expected_impact: 5.3 parameters: gov.hmrc.income_tax.rates.uk[2].rate: 0.48