Skip to content
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: 1 addition & 3 deletions .github/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def get_current_version(pyproject_path: Path) -> str:

def infer_bump(changelog_dir: Path) -> str:
fragments = [
f
for f in changelog_dir.iterdir()
if f.is_file() and f.name != ".gitkeep"
f for f in changelog_dir.iterdir() if f.is_file() and f.name != ".gitkeep"
]
if not fragments:
print("No changelog fragments found", file=sys.stderr)
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/code_changes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Check formatting
uses: "lgeiger/black-action@master"
with:
args: ". -l 79 --check"
run: uvx ruff format --check .
Test:
runs-on: macos-latest
permissions:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr_code_changes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Check formatting
uses: "lgeiger/black-action@master"
with:
args: ". -l 79 --check"
run: uvx ruff format --check .
Test:
runs-on: macos-latest
permissions:
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

## Build commands
- Install: `make install` or `pip install -e ".[dev]" --config-settings editable_mode=compat`
- Format code: `make format` or `black . -l 79`
- Format code: `make format` or `ruff format .`
- Run all tests: `make test`
- Run single test: `pytest policyengine_uk/tests/path/to/test_file.py::test_function -v`
- Generate documentation: `make documentation`
- Update changelog: `make changelog`

## Code Standards
- **Formatting**: Use Black with 79-character line length
- **Formatting**: Use Ruff formatter with 88-character line length
- **Imports**: Group imports by stdlib, third-party, local with each group alphabetized
- **Naming**: Use snake_case for variables/functions, CamelCase for classes
- **Type Hints**: Use Python type hints where possible
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install:
pip install huggingface_hub

format:
black . -l 79
ruff format .

test:
policyengine-core test policyengine_uk/tests/policy -c policyengine_uk
Expand Down
1 change: 1 addition & 0 deletions changelog.d/switch-to-ruff.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch from black to ruff format.
10 changes: 3 additions & 7 deletions docs/book/programs/gov/dcms/bbc/tv-licence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@
"\n",
"df = pd.DataFrame()\n",
"df[\"Date\"] = [\n",
" parameter.instant_str\n",
" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
" parameter.instant_str for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"]\n",
"df[\"Full TV Licence Fee\"] = [\n",
" f\"£{parameter.value:.2f}\"\n",
" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
" f\"£{parameter.value:.2f}\" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
"]\n",
"df[\"Blind TV Licence Fee\"] = [\n",
" f\"£{0.5 * parameter.value:.2f}\"\n",
Expand Down Expand Up @@ -334,9 +332,7 @@
" aged_discount[\"Change against current\"] += [\n",
" f\"{aged_discount['Reformed value'][i] - 1:.0%}\"\n",
" ]\n",
" aged_discount[\"Reformed value\"][\n",
" i\n",
" ] = f\"{aged_discount['Reformed value'][i]:.0%}\"\n",
" aged_discount[\"Reformed value\"][i] = f\"{aged_discount['Reformed value'][i]:.0%}\"\n",
" aged_discount[\"Reference\"] += [\n",
" f'<a href=\"{reference_list_ad[i]}\">Budgetary impact of changing aged discount to {aged_discount[\"Reformed value\"][i]}</a>'\n",
" ]\n",
Expand Down
16 changes: 4 additions & 12 deletions docs/book/programs/gov/dwp/pension-credit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,8 @@
"\n",
"parameters = system.parameters\n",
"\n",
"carer_addition = (\n",
" parameters.gov.dwp.pension_credit.guarantee_credit.carer.addition\n",
")\n",
"child_addition = (\n",
" parameters.gov.dwp.pension_credit.guarantee_credit.child.addition\n",
")\n",
"carer_addition = parameters.gov.dwp.pension_credit.guarantee_credit.carer.addition\n",
"child_addition = parameters.gov.dwp.pension_credit.guarantee_credit.child.addition\n",
"disabled_child = (\n",
" parameters.gov.dwp.pension_credit.guarantee_credit.child.disability.addition\n",
")\n",
Expand Down Expand Up @@ -1506,12 +1502,8 @@
"\n",
"parameters = system.parameters\n",
"\n",
"threshold_single = (\n",
" parameters.gov.dwp.pension_credit.savings_credit.threshold.SINGLE\n",
")\n",
"threshold_couple = (\n",
" parameters.gov.dwp.pension_credit.savings_credit.threshold.COUPLE\n",
")\n",
"threshold_single = parameters.gov.dwp.pension_credit.savings_credit.threshold.SINGLE\n",
"threshold_couple = parameters.gov.dwp.pension_credit.savings_credit.threshold.COUPLE\n",
"\n",
"elements = [threshold_single, threshold_couple] # [...]\n",
"\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/book/programs/gov/dwp/universal-credit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@
"disabled_child_amount = (\n",
" parameters.gov.dwp.universal_credit.elements.child.disabled.amount\n",
")\n",
"higher_amount = (\n",
" parameters.gov.dwp.universal_credit.elements.child.first.higher_amount\n",
")\n",
"higher_amount = parameters.gov.dwp.universal_credit.elements.child.first.higher_amount\n",
"\n",
"elements = [\n",
" carer_amount,\n",
Expand Down
14 changes: 5 additions & 9 deletions docs/book/programs/gov/hmrc/child-benefit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@
" data[\"Reference\"] += [\"\"]\n",
"\n",
"\n",
"for (\n",
" parameter\n",
") in parameters.gov.hmrc.child_benefit.amount.additional.values_list:\n",
"for parameter in parameters.gov.hmrc.child_benefit.amount.additional.values_list:\n",
" data[\"Date\"] += [parameter.instant_str]\n",
" data[\"Name\"] += [\"Additional\"]\n",
" data[\"Value\"] += [f\"£{parameter.value:.2f}\"]\n",
Expand All @@ -189,9 +187,9 @@
" data[\"Reference\"] += [\"\"]\n",
"\n",
"\n",
"pd.DataFrame(data).sort_values(\"Date\").set_index(\n",
" [\"Date\", \"Name\"]\n",
").style.format(lambda x: x)"
"pd.DataFrame(data).sort_values(\"Date\").set_index([\"Date\", \"Name\"]).style.format(\n",
" lambda x: x\n",
")"
]
},
{
Expand Down Expand Up @@ -302,9 +300,7 @@
"pd.DataFrame(\n",
" {\n",
" \"Number of children\": list(range(1, 7)),\n",
" \"Child Benefit (Annual)\": list(\n",
" map(get_cb_for_n_children, range(1, 7))\n",
" ),\n",
" \"Child Benefit (Annual)\": list(map(get_cb_for_n_children, range(1, 7))),\n",
" }\n",
").set_index(\"Number of children\")"
]
Expand Down
12 changes: 3 additions & 9 deletions docs/book/programs/gov/hmrc/fuel-duty.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@
"df = pd.DataFrame()\n",
"\n",
"df[\"Date of change\"] = [\n",
" parameter.instant_str\n",
" for parameter in hmrc.fuel_duty.petrol_and_diesel.values_list\n",
" parameter.instant_str for parameter in hmrc.fuel_duty.petrol_and_diesel.values_list\n",
"]\n",
"df[\"Fuel duty rate (£/litre)\"] = [\n",
" parameter.value\n",
" for parameter in hmrc.fuel_duty.petrol_and_diesel.values_list\n",
" parameter.value for parameter in hmrc.fuel_duty.petrol_and_diesel.values_list\n",
"]\n",
"df.sort_values(\"Date of change\", inplace=True)\n",
"df.set_index(\"Date of change\")"
Expand Down Expand Up @@ -1072,11 +1070,7 @@
" height=600,\n",
" width=800,\n",
" template=\"plotly_white\",\n",
").update_xaxes(\n",
" tickangle=45, tickfont={\"size\": 10}\n",
").update_traces(\n",
" line_shape=\"hv\"\n",
")"
").update_xaxes(tickangle=45, tickfont={\"size\": 10}).update_traces(line_shape=\"hv\")"
]
}
],
Expand Down
48 changes: 12 additions & 36 deletions docs/book/programs/gov/hmrc/income-tax.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@
"from policyengine_uk import Simulation\n",
"\n",
"\n",
"def calculate_taxes(\n",
" employment_income, dividend_income, savings_interest_income\n",
"):\n",
"def calculate_taxes(employment_income, dividend_income, savings_interest_income):\n",
" simulation = Simulation(\n",
" situation={\n",
" \"people\": {\n",
Expand All @@ -222,9 +220,7 @@
" }\n",
" )\n",
" income_tax = simulation.calculate(\"income_tax\")[0]\n",
" dividend_income_tax = simulation.calculate(\"dividend_income_tax\")[\n",
" 0\n",
" ] # Added\n",
" dividend_income_tax = simulation.calculate(\"dividend_income_tax\")[0] # Added\n",
" savings_income_tax = simulation.calculate(\"savings_income_tax\")[0] # Added\n",
"\n",
" return income_tax, dividend_income_tax, savings_income_tax\n",
Expand All @@ -245,9 +241,7 @@
" data[\"Dividend Income (£)\"],\n",
" data[\"Savings Interest Income (£)\"],\n",
"):\n",
" income_tax, div_tax, sav_tax = calculate_taxes(\n",
" emp_income, div_income, sav_income\n",
" )\n",
" income_tax, div_tax, sav_tax = calculate_taxes(emp_income, div_income, sav_income)\n",
" data[\"Income Tax (£)\"].append(income_tax)\n",
" data[\"Dividend Income Tax (£)\"].append(div_tax)\n",
" data[\"Savings Income Tax (£)\"].append(sav_tax)\n",
Expand Down Expand Up @@ -524,12 +518,8 @@
"from policyengine_uk.system import system\n",
"import pandas as pd\n",
"\n",
"default = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.annual_allowance.default\n",
")\n",
"minimum = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.annual_allowance.minimum\n",
")\n",
"default = system.parameters.gov.hmrc.income_tax.allowances.annual_allowance.default\n",
"minimum = system.parameters.gov.hmrc.income_tax.allowances.annual_allowance.minimum\n",
"reduction_rate = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.annual_allowance.reduction_rate\n",
")\n",
Expand Down Expand Up @@ -559,9 +549,7 @@
"\n",
"\n",
"max = system.parameters.gov.hmrc.income_tax.allowances.marriage_allowance.max\n",
"rounding_increment = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.marriage_allowance.rounding_increment\n",
")\n",
"rounding_increment = system.parameters.gov.hmrc.income_tax.allowances.marriage_allowance.rounding_increment\n",
"takeup_rate = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.marriage_allowance.takeup_rate\n",
")\n",
Expand All @@ -586,9 +574,7 @@
"}\n",
"\n",
"\n",
"deduction_rate = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.married_couples_allowance.deduction_rate\n",
")\n",
"deduction_rate = system.parameters.gov.hmrc.income_tax.allowances.married_couples_allowance.deduction_rate\n",
"married_couples_allowance_data = {\n",
" \"Attribute\": [\"Married Couples Allowance\"],\n",
" \"Type\": [\"Deduction Rate\"],\n",
Expand All @@ -598,9 +584,7 @@
"}\n",
"\n",
"\n",
"amount = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.personal_allowance.amount\n",
")\n",
"amount = system.parameters.gov.hmrc.income_tax.allowances.personal_allowance.amount\n",
"values = [item.value for item in amount.values_list]\n",
"dates = [item.instant_str for item in amount.values_list]\n",
"personal_allowance_data = {\n",
Expand All @@ -612,9 +596,7 @@
"}\n",
"\n",
"\n",
"addtional_threshold = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.personal_savings_allowance.additional\n",
")\n",
"addtional_threshold = system.parameters.gov.hmrc.income_tax.allowances.personal_savings_allowance.additional\n",
"basic_threshold = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.personal_savings_allowance.basic\n",
")\n",
Expand Down Expand Up @@ -642,9 +624,7 @@
"}\n",
"\n",
"\n",
"dividend_allowance = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.dividend_allowance\n",
")\n",
"dividend_allowance = system.parameters.gov.hmrc.income_tax.allowances.dividend_allowance\n",
"dividend_allowance_data = {\n",
" \"Attribute\": [\"Dividend Allowance\"],\n",
" \"Type\": [\"Dividend Allowance\"],\n",
Expand All @@ -654,9 +634,7 @@
"}\n",
"\n",
"\n",
"property_allowance = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.property_allowance\n",
")\n",
"property_allowance = system.parameters.gov.hmrc.income_tax.allowances.property_allowance\n",
"property_allowance_data = {\n",
" \"Attribute\": [\"Property Allowance\"],\n",
" \"Type\": [\"Property Allowance\"],\n",
Expand All @@ -666,9 +644,7 @@
"}\n",
"\n",
"\n",
"trading_allowance = (\n",
" system.parameters.gov.hmrc.income_tax.allowances.trading_allowance\n",
")\n",
"trading_allowance = system.parameters.gov.hmrc.income_tax.allowances.trading_allowance\n",
"trading_allowance_data = {\n",
" \"Attribute\": [\"Trading Allowance\"],\n",
" \"Type\": [\"Trading Allowance\"],\n",
Expand Down
12 changes: 3 additions & 9 deletions docs/book/programs/gov/hmrc/stamp-duty.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6287,9 +6287,7 @@
"stamp_duty = sim.calculate(\"stamp_duty_land_tax\")\n",
"home_price = sim.calculate(\"main_residential_property_purchased\")\n",
"\n",
"marginal_rate = (stamp_duty[1:] - stamp_duty[:-1]) / (\n",
" home_price[1:] - home_price[:-1]\n",
")\n",
"marginal_rate = (stamp_duty[1:] - stamp_duty[:-1]) / (home_price[1:] - home_price[:-1])\n",
"home_price = home_price[:-1]\n",
"\n",
"df = pd.DataFrame(\n",
Expand All @@ -6305,14 +6303,10 @@
"\n",
"# left shows marginal rate, right shows total SDLT\n",
"\n",
"fig = make_subplots(\n",
" rows=1, cols=2, subplot_titles=(\"Marginal SDLT rate\", \"Total SDLT\")\n",
")\n",
"fig = make_subplots(rows=1, cols=2, subplot_titles=(\"Marginal SDLT rate\", \"Total SDLT\"))\n",
"\n",
"fig.add_trace(\n",
" px.line(\n",
" df, x=\"Home price\", y=\"Marginal SDLT rate\", title=\"Marginal SDLT rate\"\n",
" )\n",
" px.line(df, x=\"Home price\", y=\"Marginal SDLT rate\", title=\"Marginal SDLT rate\")\n",
" .update_traces(line_shape=\"hv\")\n",
" .data[0],\n",
" row=1,\n",
Expand Down
14 changes: 5 additions & 9 deletions docs/book/programs/gov/ofgem/energy-price-guarantee.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,7 @@
"\n",
"df = pd.DataFrame()\n",
"\n",
"df[\"Date\"] = [\n",
" parameter.instant_str for parameter in ofgem.energy_price_cap.values_list\n",
"]\n",
"df[\"Date\"] = [parameter.instant_str for parameter in ofgem.energy_price_cap.values_list]\n",
"df[\"Energy price cap\"] = [\n",
" parameter.value for parameter in ofgem.energy_price_cap.values_list\n",
"]\n",
Expand Down Expand Up @@ -1107,9 +1105,9 @@
"xaxis": "x",
"y": [
8.373929949593731e-10,
1.674785989918746e-09,
2.512178984878119e-09,
3.3495719798374923e-09,
1.674785989918746e-9,
2.512178984878119e-9,
3.3495719798374923e-9,
1.2009600411861108,
2.40192007902265,
3.602880116859188,
Expand Down Expand Up @@ -1998,9 +1996,7 @@
" *[f\"2023-{month:02d}\" for month in range(1, 13)],\n",
"]\n",
"\n",
"epg_costs = [\n",
" sim.calc(\"monthly_epg_subsidy\", period).sum() for period in time_periods\n",
"]\n",
"epg_costs = [sim.calc(\"monthly_epg_subsidy\", period).sum() for period in time_periods]\n",
"\n",
"df = pd.DataFrame(\n",
" {\n",
Expand Down
Loading