Skip to content

Commit

Permalink
Add schema
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Nov 25, 2024
1 parent 46f67b6 commit 43f2b65
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 137 deletions.
60 changes: 0 additions & 60 deletions api_docs.ipynb

This file was deleted.

5 changes: 4 additions & 1 deletion docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ root: index
parts:
- caption: Maintenance
chapters:
- file: maintaining
- file: maintaining
- caption: Schema
chapters:
- file: schema
140 changes: 140 additions & 0 deletions docs/schema.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Schema\n",
"\n",
"This page contains examples of the schema of the returned simulation outputs for given types of simulation. Each subsection specifies the country, scope and whether a reform has been passed. The schema is given in YAML format.\n",
"\n",
"## UK, macro, reform-comparison"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [
{
"data": {
"text/markdown": [
"```yaml\n",
"macro:\n",
" baseline:\n",
" gov:\n",
" balance:\n",
" total_gov_spending: <class 'numpy.float64'>\n",
" total_state_tax: <class 'int'>\n",
" total_tax_revenue: <class 'numpy.float64'>\n",
" programs:\n",
" child_benefit: <class 'numpy.float64'>\n",
" council_tax: <class 'numpy.float64'>\n",
" fuel_duty: <class 'numpy.float64'>\n",
" income_tax: <class 'numpy.float64'>\n",
" national_insurance: <class 'numpy.float64'>\n",
" ni_employer: <class 'numpy.float64'>\n",
" pension_credit: <class 'numpy.float64'>\n",
" state_pension: <class 'numpy.float64'>\n",
" tax_credits: <class 'numpy.float64'>\n",
" universal_credit: <class 'numpy.float64'>\n",
" vat: <class 'numpy.float64'>\n",
" household:\n",
" demographic_values:\n",
" household_count_people: <class 'list'>\n",
" household_weight: <class 'list'>\n",
" person_weight: <class 'list'>\n",
" comparison:\n",
" revenue_impact:\n",
" tax_revenues: <class 'numpy.float64'>\n",
" reform:\n",
" gov:\n",
" balance:\n",
" total_gov_spending: <class 'numpy.float64'>\n",
" total_state_tax: <class 'int'>\n",
" total_tax_revenue: <class 'numpy.float64'>\n",
" programs:\n",
" child_benefit: <class 'numpy.float64'>\n",
" council_tax: <class 'numpy.float64'>\n",
" fuel_duty: <class 'numpy.float64'>\n",
" income_tax: <class 'numpy.float64'>\n",
" national_insurance: <class 'numpy.float64'>\n",
" ni_employer: <class 'numpy.float64'>\n",
" pension_credit: <class 'numpy.float64'>\n",
" state_pension: <class 'numpy.float64'>\n",
" tax_credits: <class 'numpy.float64'>\n",
" universal_credit: <class 'numpy.float64'>\n",
" vat: <class 'numpy.float64'>\n",
" household:\n",
" demographic_values:\n",
" household_count_people: <class 'list'>\n",
" household_weight: <class 'list'>\n",
" person_weight: <class 'list'>\n",
"\n",
"```"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from policyengine import Simulation\n",
"from IPython.display import Markdown\n",
"import yaml\n",
"\n",
"def replace_value_with_dtype(tree):\n",
" for key in tree:\n",
" if isinstance(tree[key], dict):\n",
" replace_value_with_dtype(tree[key])\n",
" else:\n",
" tree[key] = str(type(tree[key]))\n",
" return tree\n",
"\n",
"sim = Simulation(\n",
" country=\"uk\",\n",
" scope=\"macro\",\n",
" time_period=2025,\n",
" reform={\n",
" \"gov.hmrc.income_tax.allowances.personal_allowance.amount\": {\n",
" \"2025\": 0,\n",
" }\n",
" }\n",
")\n",
"sim.calculate(\"macro\")\n",
"tree = replace_value_with_dtype(sim.outputs)\n",
"\n",
"Markdown('```yaml\\n' + yaml.dump(tree, indent=2) + '\\n```')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
5 changes: 4 additions & 1 deletion policyengine/outputs/macro/comparison/revenue_impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ def revenue_impact(simulation: Simulation):
tax_revenue_reform = simulation.calculate(
"macro/reform/gov/balance"
)["total_tax_revenue"]
return tax_revenue_reform - tax_revenue_baseline
tax_revenue_impact = tax_revenue_reform - tax_revenue_baseline
return {
"tax_revenues": tax_revenue_impact,
}
75 changes: 0 additions & 75 deletions test.ipynb

This file was deleted.

0 comments on commit 43f2b65

Please sign in to comment.