diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29bb..6fc4a19a4 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: minor + changes: + changed: + - Shallow copy entities between TaxBenefitSystem objects when cloning \ No newline at end of file diff --git a/policyengine_core/taxbenefitsystems/tax_benefit_system.py b/policyengine_core/taxbenefitsystems/tax_benefit_system.py index bf4014cb9..98f812f14 100644 --- a/policyengine_core/taxbenefitsystems/tax_benefit_system.py +++ b/policyengine_core/taxbenefitsystems/tax_benefit_system.py @@ -666,6 +666,7 @@ def clone(self) -> "TaxBenefitSystem": "parameters", "_parameters_at_instant_cache", "variables", + "entities", ): new_dict[key] = value @@ -675,6 +676,7 @@ def clone(self) -> "TaxBenefitSystem": variable_name: variable.clone() for variable_name, variable in self.variables.items() } + new_dict["entities"] = [copy.copy(entity) for entity in self.entities] for entity in new_dict["entities"]: entity.set_tax_benefit_system(new) diff --git a/test.ipynb b/test.ipynb index 27c0bb532..310c0da93 100644 --- a/test.ipynb +++ b/test.ipynb @@ -9,11 +9,10 @@ "from policyengine_uk import Microsimulation\n", "from policyengine_core.reforms import Reform\n", "\n", - "reform = Reform.from_dict({\n", - " \"gov.hmrc.vat.standard_rate\": {\n", - " \"2024-01-01.2100-12-31\": 0.22\n", - " }\n", - "}, country_id=\"uk\")\n", + "reform = Reform.from_dict(\n", + " {\"gov.hmrc.vat.standard_rate\": {\"2024-01-01.2100-12-31\": 0.22}},\n", + " country_id=\"uk\",\n", + ")\n", "\n", "\n", "baseline = Microsimulation()\n", @@ -459,11 +458,23 @@ " \"diesel_spending\",\n", " \"domestic_energy_consumption\",\n", "]\n", - "baseline_income = baseline.calculate(\"household_net_income\", period=2024, map_to=\"person\")\n", - "reformed_income = reformed.calculate(\"household_net_income\", period=2024, map_to=\"person\")\n", + "baseline_income = baseline.calculate(\n", + " \"household_net_income\", period=2024, map_to=\"person\"\n", + ")\n", + "reformed_income = reformed.calculate(\n", + " \"household_net_income\", period=2024, map_to=\"person\"\n", + ")\n", "difference_income = reformed_income - baseline_income\n", "\n", - "baseline.calculate_dataframe([\"age\", \"vat\", \"consumption\", \"full_rate_vat_expenditure_rate\", *IMPUTATIONS])[difference_income > 0]" + "baseline.calculate_dataframe(\n", + " [\n", + " \"age\",\n", + " \"vat\",\n", + " \"consumption\",\n", + " \"full_rate_vat_expenditure_rate\",\n", + " *IMPUTATIONS,\n", + " ]\n", + ")[difference_income > 0]" ] } ], diff --git a/tests/core/test_yaml.py b/tests/core/test_yaml.py index acb740d10..24ad6f3c0 100644 --- a/tests/core/test_yaml.py +++ b/tests/core/test_yaml.py @@ -76,13 +76,6 @@ def test_with_reform(tax_benefit_system): ) -def test_with_extension(tax_benefit_system): - assert ( - run_yaml_test(tax_benefit_system, "test_with_extension.yaml") - == EXIT_OK - ) - - def test_with_anchors(tax_benefit_system): assert ( run_yaml_test(tax_benefit_system, "test_with_anchors.yaml") == EXIT_OK diff --git a/tests/fixtures/yaml_tests/test_with_extension.yaml b/tests/fixtures/yaml_tests/test_with_extension.yaml deleted file mode 100644 index 2677f2e6f..000000000 --- a/tests/fixtures/yaml_tests/test_with_extension.yaml +++ /dev/null @@ -1,28 +0,0 @@ -- name: "Test using an extension" - period: 2017-01 - extensions: - - policyengine_core.extension_template - input: - persons: - parent: {} - child1: {} - household: - parents: [parent] - children: [child1] - output: - local_town_child_allowance: 100 - -- name: "Test using an extension" - period: 2017-01 - extensions: - - policyengine_core.extension_template - input: - persons: - parent: {} - child1: {} - child2: {} - household: - parents: [parent] - children: [child1, child2] - output: - local_town_child_allowance: 200