Skip to content

Commit 0efd885

Browse files
Add dataset schema, remove State variables and add HBAI net income (#1155)
1 parent f429eca commit 0efd885

11 files changed

Lines changed: 81 additions & 69 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pandas as pd
2+
3+
4+
class UKDataset:
5+
person: pd.DataFrame
6+
benunit: pd.DataFrame
7+
household: pd.DataFrame
8+
9+
def __init__(
10+
self,
11+
file_path: str = None,
12+
person: pd.DataFrame = None,
13+
benunit: pd.DataFrame = None,
14+
household: pd.DataFrame = None,
15+
fiscal_year: int = 2025,
16+
):
17+
if file_path is not None:
18+
with pd.HDFStore(file_path) as f:
19+
self.person = f["person"]
20+
self.benunit = f["benunit"]
21+
self.household = f["household"]
22+
else:
23+
if person is None or benunit is None or household is None:
24+
raise ValueError(
25+
"Must provide either a file path or all three DataFrames (person, benunit, household)."
26+
)
27+
self.person = person
28+
self.benunit = benunit
29+
self.household = household
30+
31+
self.data_format = "time_period_arrays"
32+
self.time_period = fiscal_year
33+
34+
def save(self, file_path: str):
35+
with pd.HDFStore(file_path) as f:
36+
f.put("person", self.person, format="table", data_columns=True)
37+
f.put("benunit", self.benunit, format="table", data_columns=True)
38+
f.put(
39+
"household", self.household, format="table", data_columns=True
40+
)
41+
42+
def load(self):
43+
data = {}
44+
for df in (self.person, self.benunit, self.household):
45+
for col in df.columns:
46+
data[col] = {
47+
self.time_period: df[col].values,
48+
}
49+
50+
return data
51+
52+
def copy(self):
53+
return UKDataset(
54+
person=self.person.copy(),
55+
benunit=self.benunit.copy(),
56+
household=self.household.copy(),
57+
)

policyengine_uk/entities.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
# This file defines the entities needed by our legislation.
44
from policyengine_core.entities import build_entity
55

6-
State = build_entity(
7-
key="state",
8-
plural="states",
9-
label="State",
10-
roles=[
11-
{
12-
"key": "member",
13-
"plural": "members",
14-
"label": "Member",
15-
"doc": "A person who is a citizen of a country.",
16-
}
17-
],
18-
)
19-
206
Household = build_entity(
217
key="household",
228
plural="households",
@@ -57,4 +43,4 @@
5743
is_person=True,
5844
)
5945

60-
entities = [State, Household, BenUnit, Person]
46+
entities = [Household, BenUnit, Person]

policyengine_uk/variables/gov/hmrc/expected_sdlt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ def formula(household, period, parameters):
1313
if parameters(period).gov.hmrc.stamp_duty.abolish:
1414
return 0
1515
return (
16-
household.state("property_sale_rate", period)
17-
* household("stamp_duty_land_tax", period)
16+
household("stamp_duty_land_tax", period)
17+
+ parameters(period).gov.hmrc.stamp_duty.property_sale_rate
1818
) + household("corporate_sdlt", period)

policyengine_uk/variables/gov/revenue_scotland/expected_lbtt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class expected_lbtt(Variable):
99
value_type = float
1010
unit = GBP
1111

12-
def formula(household, period):
13-
property_sale_rate = household.state("property_sale_rate", period)
12+
def formula(household, period, parameters):
13+
property_sale_rate = parameters(
14+
period
15+
).gov.hmrc.stamp_duty.property_sale_rate
1416
lbtt = household("land_and_buildings_transaction_tax", period)
1517
return property_sale_rate * lbtt

policyengine_uk/variables/gov/wra/expected_ltt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class expected_ltt(Variable):
99
value_type = float
1010
unit = GBP
1111

12-
def formula(household, period):
13-
property_sale_rate = household.state("property_sale_rate", period)
12+
def formula(household, period, parameters):
13+
property_sale_rate = parameters(
14+
period
15+
).gov.hmrc.stamp_duty.property_sale_rate
1416
land_transaction_tax = household("land_transaction_tax", period)
1517
return property_sale_rate * land_transaction_tax

policyengine_uk/variables/household/consumption/property_sale_rate.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

policyengine_uk/variables/household/demographic/person_state_id.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

policyengine_uk/variables/household/demographic/person_state_role.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

policyengine_uk/variables/household/demographic/state_id.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

policyengine_uk/variables/household/demographic/state_weight.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)