Skip to content

Commit

Permalink
updated proper rounding throughout the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
masterismail committed Jul 2, 2024
1 parent 5423403 commit 5333571
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
34 changes: 12 additions & 22 deletions policyengine/economic_impact/inequality_impact/inequality_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def calculate(self) -> dict:
change_perc = (change_value / baseline_value) * 100

return {
"baseline": baseline_value,
"reform": reformed_value,
"change": change_value,
"change_percentage": change_perc
"baseline": round(baseline_value,2),
"reform": round(reformed_value,2),
"change": round(change_value,2),
"change_percentage": round(change_perc,2)
}

class Top1PctShareCalculator(BaseMetricCalculator):
Expand All @@ -100,7 +100,6 @@ def calculate(self) -> dict:
baseline_personal_hh_equiv_income.weights *= baseline_household_count_people
in_top_1_pct = baseline_personal_hh_equiv_income.percentile_rank() == 100
baseline_personal_hh_equiv_income.weights /= baseline_household_count_people

baseline_top_1_pct_share = (
baseline_personal_hh_equiv_income[in_top_1_pct].sum()
/ baseline_personal_hh_equiv_income.sum()
Expand All @@ -110,11 +109,6 @@ def calculate(self) -> dict:
reformed_household_count_people = self.calculate_reformed("household_count_people")
reformed_personal_hh_equiv_income.weights *= reformed_household_count_people
in_top_1_pct = reformed_personal_hh_equiv_income.percentile_rank() == 100





reformed_personal_hh_equiv_income.weights /= reformed_household_count_people
reformed_top_1_pct_share = (
reformed_personal_hh_equiv_income[in_top_1_pct].sum()
Expand All @@ -126,10 +120,10 @@ def calculate(self) -> dict:
change_perc = (change_value / baseline_top_1_pct_share) * 100

return {
"baseline": baseline_top_1_pct_share,
"reform": reformed_top_1_pct_share,
"change": change_value,
"change_percentage": change_perc
"baseline": round(baseline_top_1_pct_share,2),
"reform": round(reformed_top_1_pct_share,2),
"change": round(change_value,2),
"change_percentage": round(change_perc,2)
}

class Top10PctShareCalculator(BaseMetricCalculator):
Expand All @@ -153,10 +147,6 @@ def calculate(self) -> dict:
reformed_household_count_people = self.calculate_reformed("household_count_people")
reformed_personal_hh_equiv_income.weights *= reformed_household_count_people
in_top_10_pct = reformed_personal_hh_equiv_income.decile_rank() == 10




reformed_personal_hh_equiv_income.weights /= reformed_household_count_people
reformed_top_10_pct_share = (
reformed_personal_hh_equiv_income[in_top_10_pct].sum()
Expand All @@ -167,8 +157,8 @@ def calculate(self) -> dict:
change_perc = (change_value / baseline_top_10_pct_share) * 100

return {
"baseline": baseline_top_10_pct_share,
"reform": reformed_top_10_pct_share,
"change": change_value,
"change_percentage": change_perc
"baseline": round(baseline_top_10_pct_share,2),
"reform": round(reformed_top_10_pct_share,2),
"change": round(change_value,2),
"change_percentage": round(change_perc,2)
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# economic_impact_tests.yaml
- test_gini_calculator:
reform:
gov.hmrc.income_tax.rates.uk[0].rate:
"2024-01-01.2100-12-31": 0.55
country: uk
expected:
baseline: 0.4164
reform: 0.4047
change: -0.0117
change_percentage: -2.8016
baseline: 0.42
reform: 0.40
change: -0.01
change_percentage: -2.80

- test_top_1_pct_share_calculator:
reform:
gov.hmrc.income_tax.rates.uk[0].rate:
"2024-01-01.2100-12-31": 0.55
country: uk
expected:
baseline: 0.12500093238852833
reform: 0.14094821470108967
change: 0.015947282312561345
change_percentage: 12.757730688755142
baseline: 0.12
reform: 0.14
change: 0.02
change_percentage: 12.76

- test_top_10_pct_share_calculator:
reform:
gov.hmrc.income_tax.rates.uk[0].rate:
"2024-01-01.2100-12-31": 0.55
country: uk
expected:
baseline: 0.34679109636213723
reform: 0.3595809102507495
change: 0.012789813888612278
change_percentage: 3.6880456340368357
baseline: 0.35
reform: 0.36
change: 0.01
change_percentage: 3.11

0 comments on commit 5333571

Please sign in to comment.