Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shallow copy entities when cloning TaxBenefitSystem instances #288

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
changed:
- Shallow copy entities between TaxBenefitSystem objects when cloning
2 changes: 2 additions & 0 deletions policyengine_core/taxbenefitsystems/tax_benefit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ def clone(self) -> "TaxBenefitSystem":
"parameters",
"_parameters_at_instant_cache",
"variables",
"entities",
):
new_dict[key] = value

Expand All @@ -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)
Expand Down
27 changes: 19 additions & 8 deletions test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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]"
]
}
],
Expand Down
7 changes: 0 additions & 7 deletions tests/core/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 0 additions & 28 deletions tests/fixtures/yaml_tests/test_with_extension.yaml

This file was deleted.

Loading