diff --git a/.github/bump_version.py b/.github/bump_version.py index bb0fd6dd3..779a82e38 100644 --- a/.github/bump_version.py +++ b/.github/bump_version.py @@ -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) diff --git a/.github/workflows/code_changes.yaml b/.github/workflows/code_changes.yaml index dd5f5def4..bf6d11a80 100644 --- a/.github/workflows/code_changes.yaml +++ b/.github/workflows/code_changes.yaml @@ -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: diff --git a/.github/workflows/pr_code_changes.yaml b/.github/workflows/pr_code_changes.yaml index e6715f86b..501c39eaf 100644 --- a/.github/workflows/pr_code_changes.yaml +++ b/.github/workflows/pr_code_changes.yaml @@ -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: diff --git a/CLAUDE.md b/CLAUDE.md index 7613d2ae2..b297629a2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 diff --git a/Makefile b/Makefile index 3579f7b39..b7f515cd5 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/changelog.d/switch-to-ruff.changed.md b/changelog.d/switch-to-ruff.changed.md new file mode 100644 index 000000000..a514e08ff --- /dev/null +++ b/changelog.d/switch-to-ruff.changed.md @@ -0,0 +1 @@ +Switch from black to ruff format. diff --git a/docs/book/programs/gov/dcms/bbc/tv-licence.ipynb b/docs/book/programs/gov/dcms/bbc/tv-licence.ipynb index a0e13e65b..9e7123015 100644 --- a/docs/book/programs/gov/dcms/bbc/tv-licence.ipynb +++ b/docs/book/programs/gov/dcms/bbc/tv-licence.ipynb @@ -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", @@ -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'Budgetary impact of changing aged discount to {aged_discount[\"Reformed value\"][i]}'\n", " ]\n", diff --git a/docs/book/programs/gov/dwp/pension-credit.ipynb b/docs/book/programs/gov/dwp/pension-credit.ipynb index d88ca5aa4..1601aa923 100644 --- a/docs/book/programs/gov/dwp/pension-credit.ipynb +++ b/docs/book/programs/gov/dwp/pension-credit.ipynb @@ -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", @@ -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", diff --git a/docs/book/programs/gov/dwp/universal-credit.ipynb b/docs/book/programs/gov/dwp/universal-credit.ipynb index 843b7d45b..08e1146d7 100644 --- a/docs/book/programs/gov/dwp/universal-credit.ipynb +++ b/docs/book/programs/gov/dwp/universal-credit.ipynb @@ -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", diff --git a/docs/book/programs/gov/hmrc/child-benefit.ipynb b/docs/book/programs/gov/hmrc/child-benefit.ipynb index 088b1fdc7..02b915df5 100644 --- a/docs/book/programs/gov/hmrc/child-benefit.ipynb +++ b/docs/book/programs/gov/hmrc/child-benefit.ipynb @@ -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", @@ -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", + ")" ] }, { @@ -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\")" ] diff --git a/docs/book/programs/gov/hmrc/fuel-duty.ipynb b/docs/book/programs/gov/hmrc/fuel-duty.ipynb index a4ba22fff..51d676866 100644 --- a/docs/book/programs/gov/hmrc/fuel-duty.ipynb +++ b/docs/book/programs/gov/hmrc/fuel-duty.ipynb @@ -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\")" @@ -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\")" ] } ], diff --git a/docs/book/programs/gov/hmrc/income-tax.ipynb b/docs/book/programs/gov/hmrc/income-tax.ipynb index ff2491bfe..77f1fc99a 100644 --- a/docs/book/programs/gov/hmrc/income-tax.ipynb +++ b/docs/book/programs/gov/hmrc/income-tax.ipynb @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/docs/book/programs/gov/hmrc/stamp-duty.ipynb b/docs/book/programs/gov/hmrc/stamp-duty.ipynb index 9a91305d9..b7975450b 100644 --- a/docs/book/programs/gov/hmrc/stamp-duty.ipynb +++ b/docs/book/programs/gov/hmrc/stamp-duty.ipynb @@ -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", @@ -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", diff --git a/docs/book/programs/gov/ofgem/energy-price-guarantee.ipynb b/docs/book/programs/gov/ofgem/energy-price-guarantee.ipynb index 7092fee85..e23a13d53 100644 --- a/docs/book/programs/gov/ofgem/energy-price-guarantee.ipynb +++ b/docs/book/programs/gov/ofgem/energy-price-guarantee.ipynb @@ -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", @@ -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, @@ -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", diff --git a/docs/book/programs/gov/revenue_scotland/land-and-buildings-transaction-tax.ipynb b/docs/book/programs/gov/revenue_scotland/land-and-buildings-transaction-tax.ipynb index 09f4009b0..6e6400b9c 100644 --- a/docs/book/programs/gov/revenue_scotland/land-and-buildings-transaction-tax.ipynb +++ b/docs/book/programs/gov/revenue_scotland/land-and-buildings-transaction-tax.ipynb @@ -1217,9 +1217,7 @@ " color=\"Label\",\n", " title=\"Land and Buildings Transaction Tax (LBTT) rates over property price thresholds\",\n", " )\n", - " .update_layout(\n", - " yaxis_tickformat=\",.0%\", xaxis_tickprefix=\"£\", legend_title=\"\"\n", - " )\n", + " .update_layout(yaxis_tickformat=\",.0%\", xaxis_tickprefix=\"£\", legend_title=\"\")\n", " .update_traces(line_shape=\"hv\")\n", ")\n", "fig = format_fig(fig)\n", @@ -6241,9 +6239,7 @@ "lbtt_sim = sim.calculate(\"land_and_buildings_transaction_tax\")\n", "home_price = sim.calculate(\"main_residential_property_purchased\")\n", "\n", - "marginal_rate = (lbtt_sim[1:] - lbtt_sim[:-1]) / (\n", - " home_price[1:] - home_price[:-1]\n", - ")\n", + "marginal_rate = (lbtt_sim[1:] - lbtt_sim[:-1]) / (home_price[1:] - home_price[:-1])\n", "home_price = home_price[:-1]\n", "\n", "df = pd.DataFrame(\n", @@ -6259,14 +6255,10 @@ "\n", "# left shows marginal rate, right shows total LBTT\n", "\n", - "fig = make_subplots(\n", - " rows=1, cols=2, subplot_titles=(\"Marginal LBTT rate\", \"Total LBTT\")\n", - ")\n", + "fig = make_subplots(rows=1, cols=2, subplot_titles=(\"Marginal LBTT rate\", \"Total LBTT\"))\n", "\n", "fig.add_trace(\n", - " px.line(\n", - " df, x=\"Home price\", y=\"Marginal LBTT rate\", title=\"Marginal LBTT rate\"\n", - " )\n", + " px.line(df, x=\"Home price\", y=\"Marginal LBTT rate\", title=\"Marginal LBTT rate\")\n", " .update_traces(line_shape=\"hv\")\n", " .data[0],\n", " row=1,\n", diff --git a/docs/book/programs/gov/wra/land-transaction-tax.ipynb b/docs/book/programs/gov/wra/land-transaction-tax.ipynb index 12a05d5c3..80d4549ce 100644 --- a/docs/book/programs/gov/wra/land-transaction-tax.ipynb +++ b/docs/book/programs/gov/wra/land-transaction-tax.ipynb @@ -1153,9 +1153,7 @@ " color=\"Label\",\n", " title=\"Land Transaction Tax (LTT) rates over property price thresholds\",\n", " )\n", - " .update_layout(\n", - " yaxis_tickformat=\",.0%\", xaxis_tickprefix=\"£\", legend_title=\"\"\n", - " )\n", + " .update_layout(yaxis_tickformat=\",.0%\", xaxis_tickprefix=\"£\", legend_title=\"\")\n", " .update_traces(line_shape=\"hv\")\n", ")\n", "fig = format_fig(fig)\n", diff --git a/docs/book/validation/student-loan-repayments.ipynb b/docs/book/validation/student-loan-repayments.ipynb index af53e50c7..d6b90f76e 100644 --- a/docs/book/validation/student-loan-repayments.ipynb +++ b/docs/book/validation/student-loan-repayments.ipynb @@ -103,7 +103,7 @@ "\n", "print(f\"Total reported repayments: £{total_reported:.2f}bn\")\n", "print(f\"Total modelled repayments: £{total_modelled:.2f}bn\")\n", - "print(f\"Ratio (modelled/reported): {total_modelled/total_reported:.2f}\")" + "print(f\"Ratio (modelled/reported): {total_modelled / total_reported:.2f}\")" ] }, { @@ -126,22 +126,16 @@ "\n", "if has_reported.sum() > 0:\n", " # Correlation\n", - " correlation = np.corrcoef(reported[has_reported], modelled[has_reported])[\n", - " 0, 1\n", - " ]\n", + " correlation = np.corrcoef(reported[has_reported], modelled[has_reported])[0, 1]\n", " print(f\"Correlation (people with reported > 0): {correlation:.3f}\")\n", "\n", " # Match rate\n", " both_positive = (reported > 0) & (modelled > 0)\n", " match_rate = both_positive.sum() / has_reported.sum() * 100\n", - " print(\n", - " f\"People with both reported & modelled > 0: {match_rate:.1f}% of reporters\"\n", - " )\n", + " print(f\"People with both reported & modelled > 0: {match_rate:.1f}% of reporters\")\n", "\n", " # Mean values\n", - " print(\n", - " f\"\\nMean reported (reporters): £{reported[has_reported].mean():,.0f}\"\n", - " )\n", + " print(f\"\\nMean reported (reporters): £{reported[has_reported].mean():,.0f}\")\n", " print(f\"Mean modelled (reporters): £{modelled[has_reported].mean():,.0f}\")\n", " print(f\"Mean income (reporters): £{income[has_reported].mean():,.0f}\")" ] diff --git a/docs/book/validation/validation.ipynb b/docs/book/validation/validation.ipynb index 9c2fce073..2e3dc159b 100644 --- a/docs/book/validation/validation.ipynb +++ b/docs/book/validation/validation.ipynb @@ -1901,9 +1901,7 @@ " return (\n", " np.array(\n", " [\n", - " get_parameter(calibration_parameters, parameter)(\n", - " f\"{year}-01-01\"\n", - " )\n", + " get_parameter(calibration_parameters, parameter)(f\"{year}-01-01\")\n", " for year in range(2023, 2026)\n", " ]\n", " )\n", diff --git a/policyengine_uk/data/dataset_schema.py b/policyengine_uk/data/dataset_schema.py index cae7733f3..d2fa19a74 100644 --- a/policyengine_uk/data/dataset_schema.py +++ b/policyengine_uk/data/dataset_schema.py @@ -14,9 +14,7 @@ class UKSingleYearDataset: def validate_file_path(file_path: str, raise_exception: bool = True): if not file_path.endswith(".h5"): if raise_exception: - raise ValueError( - "File path must end with '.h5' for UKDataset." - ) + raise ValueError("File path must end with '.h5' for UKDataset.") return False if not Path(file_path).exists(): if raise_exception: @@ -125,9 +123,7 @@ def save(self, file_path: str): with pd.HDFStore(file_path) as f: f.put("person", self.person, format="table", data_columns=True) f.put("benunit", self.benunit, format="table", data_columns=True) - f.put( - "household", self.household, format="table", data_columns=True - ) + f.put("household", self.household, format="table", data_columns=True) f.put("time_period", pd.Series([self.time_period]), format="table") def load(self): @@ -154,9 +150,7 @@ def validate(self): raise ValueError(f"Column '{col}' contains NaN values.") @staticmethod - def from_simulation( - simulation: "Microsimulation", fiscal_year: int = 2025 - ): + def from_simulation(simulation: "Microsimulation", fiscal_year: int = 2025): entity_dfs = {} for entity in ["person", "benunit", "household"]: @@ -231,9 +225,7 @@ def __getitem__(self, fiscal_year: int): return self.get_year(fiscal_year) def save(self, file_path: str): - Path(file_path).unlink( - missing_ok=True - ) # Remove existing file if it exists + Path(file_path).unlink(missing_ok=True) # Remove existing file if it exists with pd.HDFStore(file_path) as f: for year, dataset in self.datasets.items(): f.put( @@ -262,9 +254,7 @@ def save(self, file_path: str): ) def copy(self): - new_datasets = { - year: dataset.copy() for year, dataset in self.datasets.items() - } + new_datasets = {year: dataset.copy() for year, dataset in self.datasets.items()} return UKMultiYearDataset(datasets=list(new_datasets.values())) @staticmethod diff --git a/policyengine_uk/data/economic_assumptions.py b/policyengine_uk/data/economic_assumptions.py index 4103d8666..9c6d84946 100644 --- a/policyengine_uk/data/economic_assumptions.py +++ b/policyengine_uk/data/economic_assumptions.py @@ -87,23 +87,13 @@ def apply_single_year_uprating( with open(Path(__file__).parent / "uprating_indices.yaml", "r") as f: uprating = yaml.safe_load(f) for index_name, variables in uprating.items(): - index_rel_change = parameters.get_child(index_name)( - current_year.time_period - ) + index_rel_change = parameters.get_child(index_name)(current_year.time_period) for variable in variables: - for table_name, df in zip( - current_year.table_names, current_year.tables - ): + for table_name, df in zip(current_year.table_names, current_year.tables): if variable in df.columns: - prev_year_value = getattr(previous_year, table_name)[ - variable - ] - current_year_value = prev_year_value * ( - 1 + index_rel_change - ) - getattr(current_year, table_name)[ - variable - ] = current_year_value + prev_year_value = getattr(previous_year, table_name)[variable] + current_year_value = prev_year_value * (1 + index_rel_change) + getattr(current_year, table_name)[variable] = current_year_value # Next, apply custom uprating. @@ -115,9 +105,7 @@ def apply_single_year_uprating( current_year = uprate_rent(current_year, previous_year, parameters) - current_year = uprate_student_loan_plans( - current_year, previous_year, parameters - ) + current_year = uprate_student_loan_plans(current_year, previous_year, parameters) current_year.validate() @@ -131,9 +119,7 @@ def uprate_council_tax( ): # Uprate council tax for a single year dataset. - council_tax = ( - parameters.gov.economic_assumptions.yoy_growth.obr.council_tax - ) + council_tax = parameters.gov.economic_assumptions.yoy_growth.obr.council_tax region = current_year.household["region"] country = np.select( [ @@ -162,9 +148,9 @@ def uprate_council_tax( default=0, ) - current_year.household["council_tax"] = previous_year.household[ - "council_tax" - ] * (1 + growth_rates) + current_year.household["council_tax"] = previous_year.household["council_tax"] * ( + 1 + growth_rates + ) return current_year @@ -174,9 +160,7 @@ def uprate_rent( parameters: ParameterNode, ): # Uprate rent for a single year dataset. - is_private_rented = ( - current_year.household["tenure_type"] == "RENT_PRIVATELY" - ) + is_private_rented = current_year.household["tenure_type"] == "RENT_PRIVATELY" region = current_year.household["region"] prev_rent = previous_year.household["rent"] growth = parameters.gov.economic_assumptions.yoy_growth @@ -204,9 +188,7 @@ def uprate_rent( PRIVATE_RENTAL_HOUSEHOLDS = 0.188 SOCIAL_RENTAL_HOUSEHOLDS = 0.164 - total_rental_households = ( - PRIVATE_RENTAL_HOUSEHOLDS + SOCIAL_RENTAL_HOUSEHOLDS - ) + total_rental_households = PRIVATE_RENTAL_HOUSEHOLDS + SOCIAL_RENTAL_HOUSEHOLDS private_weight = PRIVATE_RENTAL_HOUSEHOLDS / total_rental_households social_weight = SOCIAL_RENTAL_HOUSEHOLDS / total_rental_households @@ -298,10 +280,7 @@ def assign_with_probability(mask, plan_value, prob=_GRADUATE_LOAN_TAKE_UP): written_off = has_loan & (uni_start_year + _PLAN1_WRITEOFF_YEARS <= year) is_plan1_cohort = has_loan & ~written_off & (uni_start_year < 2012) is_plan2_cohort = ( - has_loan - & ~written_off - & (uni_start_year >= 2012) - & (uni_start_year < 2023) + has_loan & ~written_off & (uni_start_year >= 2012) & (uni_start_year < 2023) ) is_plan5_cohort = has_loan & ~written_off & (uni_start_year >= 2023) diff --git a/policyengine_uk/dynamics/labour_supply.py b/policyengine_uk/dynamics/labour_supply.py index e00d129f0..43f035847 100644 --- a/policyengine_uk/dynamics/labour_supply.py +++ b/policyengine_uk/dynamics/labour_supply.py @@ -44,9 +44,7 @@ def calculate_excluded_from_labour_supply_responses( """ # Exclude self-employed, full-time students, aged 60+, and adult_index == (0, >= count_adults + 1) employment_status = sim.calculate("employment_status") - self_employed = np.isin( - employment_status, ["FT_SELF_EMPLOYED", "PT_SELF_EMPLOYED"] - ) + self_employed = np.isin(employment_status, ["FT_SELF_EMPLOYED", "PT_SELF_EMPLOYED"]) student = employment_status == "STUDENT" age = sim.calculate("age") age_60_plus = age >= 60 @@ -120,16 +118,16 @@ def apply_labour_supply_responses( Returns: DataFrame with labour supply response information """ - follow_obr = sim.tax_benefit_system.parameters.gov.dynamic.obr_labour_supply_assumptions( - year + follow_obr = ( + sim.tax_benefit_system.parameters.gov.dynamic.obr_labour_supply_assumptions( + year + ) ) if (not follow_obr) or (sim.baseline is None): return # Calculate income changes using household_net_income - baseline_income = sim.baseline.calculate( - target_variable, year, map_to="person" - ) + baseline_income = sim.baseline.calculate(target_variable, year, map_to="person") reform_income = sim.calculate(target_variable, year, map_to="person") baseline_income = baseline_income @@ -164,9 +162,7 @@ def apply_labour_supply_responses( substitution_response_ftes=progression_responses[ "substitution_response_ftes" ].sum(), - income_response_ftes=progression_responses[ - "income_response_ftes" - ].sum(), + income_response_ftes=progression_responses["income_response_ftes"].sum(), total_response_ftes=progression_responses["total_response_ftes"].sum(), participation_response_employment=( participation_responses["participation_change"].sum() @@ -248,17 +244,12 @@ def apply_progression_responses( gross_wage * derivative_changes["deriv_scenario"] ) derivative_changes["wage_rel_change"] = ( - ( - derivative_changes["wage_scenario"] - / derivative_changes["wage_baseline"] - - 1 - ) + (derivative_changes["wage_scenario"] / derivative_changes["wage_baseline"] - 1) .replace([np.inf, -np.inf, np.nan], 0) .fillna(0) ) derivative_changes["wage_abs_change"] = ( - derivative_changes["wage_scenario"] - - derivative_changes["wage_baseline"] + derivative_changes["wage_scenario"] - derivative_changes["wage_baseline"] ) # Calculate changes in income levels (drives income effects) @@ -273,9 +264,7 @@ def apply_progression_responses( } ) else: - income_changes = calculate_relative_income_change( - sim, target_variable, year - ) + income_changes = calculate_relative_income_change(sim, target_variable, year) income_changes = income_changes.rename( columns={col: f"income_{col}" for col in income_changes.columns} @@ -315,10 +304,7 @@ def apply_progression_responses( "total_response", ]: df[f"{response_type}_ftes"] = ( - df[response_type] - / df["employment_income"] - * df["hours_per_week"] - / 37.5 + df[response_type] / df["employment_income"] * df["hours_per_week"] / 37.5 ) excluded = calculate_excluded_from_labour_supply_responses( diff --git a/policyengine_uk/dynamics/participation.py b/policyengine_uk/dynamics/participation.py index 39f20fd50..c39d521b9 100644 --- a/policyengine_uk/dynamics/participation.py +++ b/policyengine_uk/dynamics/participation.py @@ -38,9 +38,7 @@ def calculate_participation_elasticities( # Get partner employment status for married individuals is_household_head = sim.calculate("is_household_head", map_to="person") - benunit_count_adults = sim.calculate( - "benunit_count_adults", map_to="person" - ) + benunit_count_adults = sim.calculate("benunit_count_adults", map_to="person") employment_income = sim.calculate("employment_income") benunit_id = sim.calculate("benunit_id", map_to="person") adult_index = sim.calculate("adult_index") @@ -56,14 +54,10 @@ def calculate_participation_elasticities( ) # Calculate total employed adults per benunit - benunit_employed = ( - df[df["is_adult"]].groupby("benunit_id")["employed"].sum() - ) + benunit_employed = df[df["is_adult"]].groupby("benunit_id")["employed"].sum() # Map back to individuals - employed_adults_in_benunit = ( - df["benunit_id"].map(benunit_employed).fillna(0) - ) + employed_adults_in_benunit = df["benunit_id"].map(benunit_employed).fillna(0) # Partner is employed if: 2-adult benunit and (both employed OR person not employed but other is) partner_employed = (benunit_count_adults == 2) & ( @@ -79,9 +73,7 @@ def calculate_participation_elasticities( # Men (except lone fathers) "men": np.array([0.227, 0.182, 0.136, 0.091, 0.023]), # Single women without children - "single_women_no_children": np.array( - [0.216, 0.173, 0.130, 0.086, 0.022] - ), + "single_women_no_children": np.array([0.216, 0.173, 0.130, 0.086, 0.022]), # Women without children, non-working partner "women_no_children_nonworking_partner": np.array( [0.216, 0.173, 0.130, 0.086, 0.022] @@ -96,43 +88,25 @@ def calculate_participation_elasticities( "lone_parent_6_10": np.array([1.195, 0.956, 0.717, 0.478, 0.120]), "lone_parent_11_plus": np.array([0.797, 0.637, 0.478, 0.319, 0.080]), # Women with non-working partner by youngest child age - "women_nonworking_partner_0_2": np.array( - [0.324, 0.259, 0.194, 0.129, 0.032] - ), - "women_nonworking_partner_3_5": np.array( - [0.421, 0.336, 0.253, 0.168, 0.042] - ), - "women_nonworking_partner_6_10": np.array( - [0.324, 0.259, 0.194, 0.130, 0.033] - ), + "women_nonworking_partner_0_2": np.array([0.324, 0.259, 0.194, 0.129, 0.032]), + "women_nonworking_partner_3_5": np.array([0.421, 0.336, 0.253, 0.168, 0.042]), + "women_nonworking_partner_6_10": np.array([0.324, 0.259, 0.194, 0.130, 0.033]), "women_nonworking_partner_11_plus": np.array( [0.216, 0.173, 0.130, 0.086, 0.021] ), # Women with working partner by youngest child age - "women_working_partner_0_2": np.array( - [0.755, 0.604, 0.453, 0.302, 0.076] - ), - "women_working_partner_3_5": np.array( - [0.982, 0.786, 0.589, 0.393, 0.098] - ), - "women_working_partner_6_10": np.array( - [0.755, 0.604, 0.453, 0.302, 0.076] - ), - "women_working_partner_11_plus": np.array( - [0.504, 0.403, 0.302, 0.201, 0.051] - ), + "women_working_partner_0_2": np.array([0.755, 0.604, 0.453, 0.302, 0.076]), + "women_working_partner_3_5": np.array([0.982, 0.786, 0.589, 0.393, 0.098]), + "women_working_partner_6_10": np.array([0.755, 0.604, 0.453, 0.302, 0.076]), + "women_working_partner_11_plus": np.array([0.504, 0.403, 0.302, 0.201, 0.051]), } # Vectorized assignment function def assign_elasticities(mask, elasticity_key): if mask.any(): # Ensure quintiles are in valid range - valid_quintiles = np.clip( - earnings_quintile[mask] - 1, 0, 4 - ).astype(int) - elasticities[mask] = elasticity_matrices[elasticity_key][ - valid_quintiles - ] + valid_quintiles = np.clip(earnings_quintile[mask] - 1, 0, 4).astype(int) + elasticities[mask] = elasticity_matrices[elasticity_key][valid_quintiles] # Men (except lone fathers) men_not_lone_parent = (gender == "MALE") & ~(is_single & has_children) @@ -155,9 +129,7 @@ def assign_elasticities(mask, elasticity_key): # Lone parents by youngest child age lone_parents = (gender == "FEMALE") & is_single & has_children - assign_elasticities( - lone_parents & (youngest_child_age <= 2), "lone_parent_0_2" - ) + assign_elasticities(lone_parents & (youngest_child_age <= 2), "lone_parent_0_2") assign_elasticities( lone_parents & (youngest_child_age >= 3) & (youngest_child_age <= 5), "lone_parent_3_5", @@ -203,15 +175,11 @@ def assign_elasticities(mask, elasticity_key): "women_working_partner_0_2", ) assign_elasticities( - women_working_partner - & (youngest_child_age >= 3) - & (youngest_child_age <= 5), + women_working_partner & (youngest_child_age >= 3) & (youngest_child_age <= 5), "women_working_partner_3_5", ) assign_elasticities( - women_working_partner - & (youngest_child_age >= 6) - & (youngest_child_age <= 10), + women_working_partner & (youngest_child_age >= 6) & (youngest_child_age <= 10), "women_working_partner_6_10", ) assign_elasticities( @@ -245,9 +213,7 @@ def impute_wages_for_nonworkers( # Calculate hourly wages for workers working_mask = (employment_income > 0) & (hours_worked > 0) - hourly_wages = np.where( - working_mask, employment_income / (hours_worked * 52), 0 - ) + hourly_wages = np.where(working_mask, employment_income / (hours_worked * 52), 0) # Get elasticity groups for wage calculation earnings_quintile = calculate_earnings_quintile( @@ -300,16 +266,12 @@ def calculate_gain_to_work( # Get current employment status and income employment_income = sim.calculate("employment_income", year) hours_worked = sim.calculate("hours_worked", year) - household_net_income = sim.calculate( - "household_net_income", year, map_to="person" - ) + household_net_income = sim.calculate("household_net_income", year, map_to="person") adult_index = sim.calculate("adult_index") # Impute wages for non-workers if requested if impute_nonworker_wages: - imputed_wages = impute_wages_for_nonworkers( - sim, year, hours_for_new_entrants - ) + imputed_wages = impute_wages_for_nonworkers(sim, year, hours_for_new_entrants) # For non-workers, use imputed wages; for workers, use actual income working_mask = employment_income > 0 employment_income_with_imputation = np.where( @@ -436,9 +398,7 @@ def apply_participation_responses( # Calculate excluded individuals from .labour_supply import calculate_excluded_from_labour_supply_responses - excluded = calculate_excluded_from_labour_supply_responses( - sim, count_adults - ) + excluded = calculate_excluded_from_labour_supply_responses(sim, count_adults) # Get employment status employment_income = sim.calculate("employment_income", year) @@ -493,9 +453,7 @@ def apply_participation_responses( replacement_rate[positive_in_work] = ( out_of_work_income[positive_in_work] / in_work_income[positive_in_work] ) - replacement_rate = np.clip( - replacement_rate, 0, 1 - ) # Ensure between 0 and 1 + replacement_rate = np.clip(replacement_rate, 0, 1) # Ensure between 0 and 1 # Transform elasticities elasticities = elasticities_wrt_income * (1 - replacement_rate) @@ -511,9 +469,7 @@ def apply_participation_responses( # that pushes non-workers further away from employment # Group people by elasticity group for surplus calculation - elasticity_groups = pd.cut( - elasticities, bins=20, labels=False, duplicates="drop" - ) + elasticity_groups = pd.cut(elasticities, bins=20, labels=False, duplicates="drop") surplus_participation_change = np.zeros_like(direct_participation_change) @@ -536,9 +492,7 @@ def apply_participation_responses( ) # Similarly, non-worker GTW changes affect workers (pushing them out if negative) - avg_nonworker_gtw_change = np.mean( - gtw_pct_change[nonworkers_in_group] - ) + avg_nonworker_gtw_change = np.mean(gtw_pct_change[nonworkers_in_group]) surplus_participation_change[workers_in_group] = ( elasticities[workers_in_group] * avg_nonworker_gtw_change @@ -546,9 +500,7 @@ def apply_participation_responses( ) # Total participation change includes both direct and surplus effects - participation_change = ( - direct_participation_change + surplus_participation_change - ) + participation_change = direct_participation_change + surplus_participation_change # Apply stochastic participation responses new_employment_income = employment_income.copy() @@ -565,9 +517,7 @@ def apply_participation_responses( participation_response[i] = True # Exited work # For currently non-working individuals: chance of entering work - imputed_wages = impute_wages_for_nonworkers( - sim, year, hours_for_new_entrants - ) + imputed_wages = impute_wages_for_nonworkers(sim, year, hours_for_new_entrants) for i in np.where(currently_not_working)[0]: # Positive participation change means higher probability of working entry_probability = max( @@ -624,6 +574,4 @@ def apply_participation_responses( weighted_results = MicroDataFrame(results, weights=weights) - return weighted_results[~weighted_results.excluded].drop( - columns=["excluded"] - ) + return weighted_results[~weighted_results.excluded].drop(columns=["excluded"]) diff --git a/policyengine_uk/dynamics/progression.py b/policyengine_uk/dynamics/progression.py index 565ff3c01..7c4735c2d 100644 --- a/policyengine_uk/dynamics/progression.py +++ b/policyengine_uk/dynamics/progression.py @@ -43,9 +43,7 @@ def calculate_derivative( entity_key = sim.tax_benefit_system.variables[input_variable].entity.key # Calculate baseline target values - original_target_values = sim.calculate( - target_variable, year, map_to=entity_key - ) + original_target_values = sim.calculate(target_variable, year, map_to=entity_key) new_target_values = original_target_values.copy() # Apply delta change to each adult sequentially to calculate marginal effects @@ -63,9 +61,9 @@ def calculate_derivative( rel_marginal_wages = (new_target_values - original_target_values) / delta # Set non-adult observations to NaN - rel_marginal_wages[ - ~pd.Series(adult_index).isin(range(1, count_adults + 1)) - ] = np.nan + rel_marginal_wages[~pd.Series(adult_index).isin(range(1, count_adults + 1))] = ( + np.nan + ) # Reset simulation to original state sim.reset_calculations() @@ -97,9 +95,7 @@ def calculate_relative_income_change( original_target_values = sim.baseline.calculate( target_variable, year, map_to="person" ) - reformed_target_values = sim.calculate( - target_variable, year, map_to="person" - ) + reformed_target_values = sim.calculate(target_variable, year, map_to="person") original_target_values = pd.Series( original_target_values, index=reformed_target_values.index ) @@ -290,9 +286,9 @@ def calculate_labour_net_income_elasticities( ) # Stronger negative income effects with younger children - elasticities[married_women & has_children & (youngest_child_age <= 2)] = ( - -0.185 - ) # 0-2 years + elasticities[ + married_women & has_children & (youngest_child_age <= 2) + ] = -0.185 # 0-2 years elasticities[ married_women & has_children @@ -305,15 +301,13 @@ def calculate_labour_net_income_elasticities( & (youngest_child_age >= 5) & (youngest_child_age <= 10) ] = -0.102 # 5-10 years - elasticities[married_women & has_children & (youngest_child_age >= 11)] = ( - -0.063 - ) # 11+ years + elasticities[ + married_women & has_children & (youngest_child_age >= 11) + ] = -0.063 # 11+ years # Lone parents - smaller negative income effects than married women lone_parents = (gender == "FEMALE") & ~is_married & has_children - elasticities[lone_parents & (youngest_child_age <= 4)] = ( - -0.037 - ) # 0-4 years + elasticities[lone_parents & (youngest_child_age <= 4)] = -0.037 # 0-4 years elasticities[ lone_parents & (youngest_child_age >= 5) & (youngest_child_age <= 10) ] = -0.075 # 5-10 years @@ -362,9 +356,7 @@ def calculate_employment_income_change( # Calculate income effect: response to changes in unearned income income_response = ( - employment_income - * income_changes["income_rel_change"] - * income_elasticities + employment_income * income_changes["income_rel_change"] * income_elasticities ) # Total labour supply response is sum of substitution and income effects diff --git a/policyengine_uk/microsimulation.py b/policyengine_uk/microsimulation.py index 66b57f720..1e5e6e45d 100644 --- a/policyengine_uk/microsimulation.py +++ b/policyengine_uk/microsimulation.py @@ -100,6 +100,4 @@ def compare( df = super().compare( other, variables=variables, period=period, change_only=change_only ) - return MicroDataFrame( - df, weights=self.get_weights(variables[0], period) - ) + return MicroDataFrame(df, weights=self.get_weights(variables[0], period)) diff --git a/policyengine_uk/parameters/gov/dwp/LHA/__init__.py b/policyengine_uk/parameters/gov/dwp/LHA/__init__.py index 76d935c80..3d0d3e4eb 100644 --- a/policyengine_uk/parameters/gov/dwp/LHA/__init__.py +++ b/policyengine_uk/parameters/gov/dwp/LHA/__init__.py @@ -1,6 +1,4 @@ import pandas as pd from pathlib import Path -lha_list_of_rents = pd.read_csv( - Path(__file__).parent / "lha_list_of_rents.csv.gz" -) +lha_list_of_rents = pd.read_csv(Path(__file__).parent / "lha_list_of_rents.csv.gz") diff --git a/policyengine_uk/parameters/gov/dwp/state_pension/triple_lock/create_triple_lock.py b/policyengine_uk/parameters/gov/dwp/state_pension/triple_lock/create_triple_lock.py index 2da97a6ad..92763ff8b 100644 --- a/policyengine_uk/parameters/gov/dwp/state_pension/triple_lock/create_triple_lock.py +++ b/policyengine_uk/parameters/gov/dwp/state_pension/triple_lock/create_triple_lock.py @@ -20,12 +20,8 @@ def add_triple_lock(parameters: ParameterNode) -> ParameterNode: earnings_increase = average_earnings(year - 1) cpi_increase = cpi(year - 1) min_rate_y = min_rate(year) - if triple_lock.include_earnings( - year - ) and triple_lock.include_inflation(year): - triple_lock_increase = max( - earnings_increase, cpi_increase, min_rate_y - ) + if triple_lock.include_earnings(year) and triple_lock.include_inflation(year): + triple_lock_increase = max(earnings_increase, cpi_increase, min_rate_y) elif triple_lock.include_earnings(year): triple_lock_increase = max(earnings_increase, min_rate_y) elif triple_lock.include_inflation(year): diff --git a/policyengine_uk/parameters/gov/economic_assumptions/create_economic_assumption_indices.py b/policyengine_uk/parameters/gov/economic_assumptions/create_economic_assumption_indices.py index 01072eb49..f87f0b7f5 100644 --- a/policyengine_uk/parameters/gov/economic_assumptions/create_economic_assumption_indices.py +++ b/policyengine_uk/parameters/gov/economic_assumptions/create_economic_assumption_indices.py @@ -50,8 +50,7 @@ def create_economic_assumption_indices( name=descendant.name.replace("yoy_growth", "indices"), data={ "values": { - f"{year}-01-01": value - for year, value in values.items() + f"{year}-01-01": value for year, value in values.items() }, }, ) diff --git a/policyengine_uk/parameters/gov/economic_assumptions/lag_average_earnings.py b/policyengine_uk/parameters/gov/economic_assumptions/lag_average_earnings.py index 76d06233a..130fd2d59 100644 --- a/policyengine_uk/parameters/gov/economic_assumptions/lag_average_earnings.py +++ b/policyengine_uk/parameters/gov/economic_assumptions/lag_average_earnings.py @@ -14,8 +14,7 @@ def add_lagged_earnings( "gov.economic_assumptions.yoy_growth.lagged_average_earnings", data={ "values": { - f"{year}-01-01": earnings(year - 1) - for year in range(2022, 2030) + f"{year}-01-01": earnings(year - 1) for year in range(2022, 2030) }, }, ) diff --git a/policyengine_uk/parameters/gov/economic_assumptions/lag_cpi.py b/policyengine_uk/parameters/gov/economic_assumptions/lag_cpi.py index 531300e1b..110adbbb0 100644 --- a/policyengine_uk/parameters/gov/economic_assumptions/lag_cpi.py +++ b/policyengine_uk/parameters/gov/economic_assumptions/lag_cpi.py @@ -13,9 +13,7 @@ def add_lagged_cpi( lagged_cpi = Parameter( "gov.economic_assumptions.yoy_growth.obr.lagged_cpi", data={ - "values": { - f"{year}-01-01": cpi(year - 1) for year in range(2010, 2030) - }, + "values": {f"{year}-01-01": cpi(year - 1) for year in range(2010, 2030)}, }, ) diff --git a/policyengine_uk/parameters/gov/hmrc/fuel_duty/calculate_fuel_duty_rates.py b/policyengine_uk/parameters/gov/hmrc/fuel_duty/calculate_fuel_duty_rates.py index f7864b055..082e6122b 100644 --- a/policyengine_uk/parameters/gov/hmrc/fuel_duty/calculate_fuel_duty_rates.py +++ b/policyengine_uk/parameters/gov/hmrc/fuel_duty/calculate_fuel_duty_rates.py @@ -218,9 +218,7 @@ def generate_year_breakdown( if rate != current_rate: if current_rate is not None: days = (prev_date - period_start).days + 1 - periods.append( - (period_start, prev_date, current_rate, days) - ) + periods.append((period_start, prev_date, current_rate, days)) current_rate = rate period_start = d prev_date = d @@ -263,9 +261,7 @@ def generate_note_for_year( # Add formula formula_parts = [f"{rate:.2f}p * {days}" for _, _, rate, days in periods] - lines.append( - f"({' + '.join(formula_parts)}) / {total_days} = {avg_pence:.2f}p" - ) + lines.append(f"({' + '.join(formula_parts)}) / {total_days} = {avg_pence:.2f}p") lines.append("Generated by calculate_fuel_duty_rates.py") return "\n".join(lines) @@ -298,9 +294,7 @@ def update_yaml_file( # Pattern to match existing entry for this year # Matches from the date line until the next date or metadata section - pattern = ( - rf"( {date_str}:.*?)(?=\n \d{{4}}-\d{{2}}-\d{{2}}:|\nmetadata:)" - ) + pattern = rf"( {date_str}:.*?)(?=\n \d{{4}}-\d{{2}}-\d{{2}}:|\nmetadata:)" # New entry text new_entry = f""" {date_str}: @@ -321,12 +315,7 @@ def update_yaml_file( metadata_match = re.search(r"\nmetadata:", content) if metadata_match: insert_pos = metadata_match.start() - content = ( - content[:insert_pos] - + "\n" - + new_entry - + content[insert_pos:] - ) + content = content[:insert_pos] + "\n" + new_entry + content[insert_pos:] # Write the updated content back with open(yaml_path, "w") as f: @@ -347,9 +336,7 @@ def print_calculations( print(f" Pre-cut rate (2021-01-01): {pre_cut_rate:.2f}p") print() - print( - "RPI forecasts from yoy_growth.yaml (applied in April of next year):" - ) + print("RPI forecasts from yoy_growth.yaml (applied in April of next year):") for year in CALCULATION_YEARS: rpi = rpi_forecasts.get(year, 0) print(f" {year}: {rpi:.2f}%") @@ -374,9 +361,7 @@ def print_calculations( date(2030, 4, 1), ] for d in key_dates: - rate = get_rate_on_date( - d, base_rate_with_cut, pre_cut_rate, rpi_forecasts - ) + rate = get_rate_on_date(d, base_rate_with_cut, pre_cut_rate, rpi_forecasts) print(f" {d}: {rate:.2f}p ({format_as_pounds(rate)} GBP)") print() diff --git a/policyengine_uk/reforms/cps/marriage_tax_reforms.py b/policyengine_uk/reforms/cps/marriage_tax_reforms.py index 1fbe3b5b3..98b045fd1 100644 --- a/policyengine_uk/reforms/cps/marriage_tax_reforms.py +++ b/policyengine_uk/reforms/cps/marriage_tax_reforms.py @@ -16,9 +16,7 @@ def formula(person, period): # There is a child who either meets the age condition or the education condition benunit = person.benunit if max_child_age is not None: - child_meets_age_condition = ( - person("age", period) <= max_child_age - ) + child_meets_age_condition = person("age", period) <= max_child_age return benunit.any(child_meets_age_condition) if child_education_levels is not None: child_meets_education_condition = np.is_in( @@ -54,9 +52,7 @@ class marriage_allowance(Variable): entity = Person label = "Marriage Allowance" definition_period = YEAR - reference = ( - "https://www.legislation.gov.uk/ukpga/2007/3/part/3/chapter/3A" - ) + reference = "https://www.legislation.gov.uk/ukpga/2007/3/part/3/chapter/3A" unit = GBP def formula(person, period, parameters): @@ -65,9 +61,7 @@ def formula(person, period, parameters): eligible = married & person( "meets_marriage_allowance_income_conditions", period ) - transferable_amount = person( - "partners_unused_personal_allowance", period - ) + transferable_amount = person("partners_unused_personal_allowance", period) allowances = parameters(period).gov.hmrc.income_tax.allowances takeup_rate = allowances.marriage_allowance.takeup_rate capped_percentage = allowances.marriage_allowance.max @@ -79,16 +73,10 @@ def formula(person, period, parameters): expanded_ma_cap, capped_percentage, ) - max_amount = ( - allowances.personal_allowance.amount * capped_percentage - ) - amount_if_eligible_pre_rounding = min_( - transferable_amount, max_amount - ) + max_amount = allowances.personal_allowance.amount * capped_percentage + amount_if_eligible_pre_rounding = min_(transferable_amount, max_amount) # Round up. - rounding_increment = ( - allowances.marriage_allowance.rounding_increment - ) + rounding_increment = allowances.marriage_allowance.rounding_increment amount_if_eligible = ( np.ceil(amount_if_eligible_pre_rounding / rounding_increment) * rounding_increment @@ -119,9 +107,7 @@ def formula(person, period): # There is a child who either meets the age condition or the education condition benunit = person.benunit if max_child_age is not None: - child_meets_age_condition = ( - person("age", period) <= max_child_age - ) + child_meets_age_condition = person("age", period) <= max_child_age return benunit.any(child_meets_age_condition) if child_education_levels is not None: child_meets_education_condition = np.is_in( @@ -187,9 +173,7 @@ def formula(person, period, parameters): split_income_branch = person.simulation.get_branch( "split_income", clone_system=True ) - split_income_branch.set_input( - "adjusted_net_income", period, split_income - ) + split_income_branch.set_input("adjusted_net_income", period, split_income) split_income_tax = person.benunit.sum( split_income_branch.calculate("income_tax", period) ) diff --git a/policyengine_uk/reforms/policyengine/adjust_budgets.py b/policyengine_uk/reforms/policyengine/adjust_budgets.py index 56354ce15..e010c853c 100644 --- a/policyengine_uk/reforms/policyengine/adjust_budgets.py +++ b/policyengine_uk/reforms/policyengine/adjust_budgets.py @@ -23,9 +23,7 @@ def adjust_budgets(parameters, period): reforms = [] for baseline_parameter, parameter, budget_variable in budgets: - budget_reform = adjust_budget( - baseline_parameter, parameter, budget_variable - ) + budget_reform = adjust_budget(baseline_parameter, parameter, budget_variable) if budget_reform is not None: reforms.append(budget_reform) diff --git a/policyengine_uk/reforms/policyengine/disable_simulated_benefits.py b/policyengine_uk/reforms/policyengine/disable_simulated_benefits.py index dc9db733e..54338e3e9 100644 --- a/policyengine_uk/reforms/policyengine/disable_simulated_benefits.py +++ b/policyengine_uk/reforms/policyengine/disable_simulated_benefits.py @@ -45,20 +45,14 @@ def apply(self): reported_value = simulation.calculate( variable + "_reported", time_period, map_to=entity ) - for year in range( - time_period, time_period + YEARS_IN_FUTURE - ): + for year in range(time_period, time_period + YEARS_IN_FUTURE): simulation.set_input(variable, year, reported_value) if variable in ["child_tax_credit", "working_tax_credit"]: # CTC and WTC have their own pre_minimum variables because tax credits aren't paid if # below a threshold. variable = variable + "_pre_minimum" - for year in range( - time_period, time_period + YEARS_IN_FUTURE - ): - simulation.set_input( - variable, year, reported_value - ) + for year in range(time_period, time_period + YEARS_IN_FUTURE): + simulation.set_input(variable, year, reported_value) return DisableSimulatedBenefits diff --git a/policyengine_uk/reforms/scotland/scottish_child_payment_reform.py b/policyengine_uk/reforms/scotland/scottish_child_payment_reform.py index 9162e6c60..44910e585 100644 --- a/policyengine_uk/reforms/scotland/scottish_child_payment_reform.py +++ b/policyengine_uk/reforms/scotland/scottish_child_payment_reform.py @@ -34,15 +34,11 @@ class scottish_child_payment(Variable): def formula(person, period, parameters): # Get base SCP rate - p = parameters( - period - ).gov.social_security_scotland.scottish_child_payment + p = parameters(period).gov.social_security_scotland.scottish_child_payment base_weekly = p.amount # Get reform parameters - scp_reform = parameters( - period - ).gov.contrib.scotland.scottish_child_payment + scp_reform = parameters(period).gov.contrib.scotland.scottish_child_payment in_effect = scp_reform.in_effect under_one = scp_reform.under_one @@ -68,9 +64,7 @@ def apply(self): return reform -def create_scottish_child_payment_reform( - parameters, period, bypass: bool = False -): +def create_scottish_child_payment_reform(parameters, period, bypass: bool = False): if bypass: return create_scottish_child_payment_baby_bonus_reform() @@ -92,6 +86,4 @@ def create_scottish_child_payment_reform( return None -scottish_child_payment_reform = ( - create_scottish_child_payment_baby_bonus_reform() -) +scottish_child_payment_reform = create_scottish_child_payment_baby_bonus_reform() diff --git a/policyengine_uk/scenarios/reindex_benefit_cap.py b/policyengine_uk/scenarios/reindex_benefit_cap.py index 939074243..8d33eb70a 100644 --- a/policyengine_uk/scenarios/reindex_benefit_cap.py +++ b/policyengine_uk/scenarios/reindex_benefit_cap.py @@ -19,9 +19,7 @@ def index_benefit_cap(simulation: Simulation): parameter: Parameter # Type annotation # Delete all values after 2025 parameter.values_list = [ - entry - for entry in parameter.values_list - if entry.instant_str < "2026-01-01" + entry for entry in parameter.values_list if entry.instant_str < "2026-01-01" ] parameter.metadata.update( uprating="gov.benefit_uprating_cpi", diff --git a/policyengine_uk/scenarios/uc_reform.py b/policyengine_uk/scenarios/uc_reform.py index 1b91c0d1c..cd0f4e3a7 100644 --- a/policyengine_uk/scenarios/uc_reform.py +++ b/policyengine_uk/scenarios/uc_reform.py @@ -4,9 +4,7 @@ def add_universal_credit_reform(sim: Microsimulation): - rebalancing = ( - sim.tax_benefit_system.parameters.gov.dwp.universal_credit.rebalancing - ) + rebalancing = sim.tax_benefit_system.parameters.gov.dwp.universal_credit.rebalancing generator = np.random.default_rng(43) @@ -26,9 +24,7 @@ def add_universal_credit_reform(sim: Microsimulation): current_health_element = sim.calculate("uc_LCWRA_element", year) # Set new claimants to £217.26/month from April 2026 (pre-2026 claimaints keep inflation-linked increases) # https://bills.parliament.uk/publications/62123/documents/6889#page=16 - current_health_element[ - (current_health_element > 0) & is_post_25_claimant - ] = ( + current_health_element[(current_health_element > 0) & is_post_25_claimant] = ( new_claimant_health_element(year) * 12 ) # Monthly amount * 12 sim.set_input("uc_LCWRA_element", year, current_health_element) diff --git a/policyengine_uk/simulation.py b/policyengine_uk/simulation.py index fddfe34cb..4f6bc1822 100644 --- a/policyengine_uk/simulation.py +++ b/policyengine_uk/simulation.py @@ -115,9 +115,7 @@ def __init__( self.invalidated_caches = set() self.debug: bool = False self.trace: bool = trace - self.tracer: SimpleTracer = ( - SimpleTracer() if not trace else FullTracer() - ) + self.tracer: SimpleTracer = SimpleTracer() if not trace else FullTracer() self.opt_out_cache: bool = False self.max_spiral_loops: int = 10 self.memory_config = None @@ -212,9 +210,7 @@ def apply_parameter_changes(self, changes: dict): self.tax_benefit_system.reset_parameters() for parameter in changes: - p: Parameter = self.tax_benefit_system.parameters.get_child( - parameter - ) + p: Parameter = self.tax_benefit_system.parameters.get_child(parameter) if isinstance(changes[parameter], dict): # Time-period specific changes for time_period in changes[parameter]: @@ -233,9 +229,7 @@ def build_from_situation(self, situation: Dict) -> None: Args: situation: Dictionary describing household composition and characteristics """ - self.build_from_populations( - self.tax_benefit_system.instantiate_entities() - ) + self.build_from_populations(self.tax_benefit_system.instantiate_entities()) from policyengine_core.simulations.simulation_builder import ( SimulationBuilder, ) # Import here to avoid circular dependency @@ -259,9 +253,7 @@ def build_from_url(self, url: str) -> None: ValueError: If URL is not a HuggingFace URL """ if "hf://" not in url: - raise ValueError( - f"Non-HuggingFace URLs are currently not supported." - ) + raise ValueError(f"Non-HuggingFace URLs are currently not supported.") # Return early from in-memory cache if available: skips HDF5 reading, # uprating and enum encoding (~2.2s on the first load). @@ -295,9 +287,7 @@ def build_from_url(self, url: str) -> None: self.tax_benefit_system.parameters, ) else: - dataset = Dataset.from_file( - dataset_file, self.default_input_period - ) + dataset = Dataset.from_file(dataset_file, self.default_input_period) self.build_from_dataset(dataset) return @@ -361,9 +351,7 @@ def build_from_dataset(self, dataset: Dataset) -> None: Args: dataset: PolicyEngine Dataset object containing simulation data """ - data: Dict[str, Dict[str, Union[float, int, str]]] = ( - dataset.load_dataset() - ) + data: Dict[str, Dict[str, Union[float, int, str]]] = dataset.load_dataset() first_variable = data[list(data.keys())[0]] first_time_period = list(first_variable.keys())[0] @@ -392,9 +380,7 @@ def get_first_array(variable_name: str) -> np.ndarray: for time_period in data[variable]: if variable not in self.tax_benefit_system.variables: continue - self.set_input( - variable, time_period, data[variable][time_period] - ) + self.set_input(variable, time_period, data[variable][time_period]) # Now convert to the new UKSingleYearDataset self.input_variables = self.get_known_variables() @@ -409,9 +395,7 @@ def get_first_array(variable_name: str) -> np.ndarray: self.build_from_multi_year_dataset(multi_year_dataset) self.dataset = multi_year_dataset - def build_from_single_year_dataset( - self, dataset: UKSingleYearDataset - ) -> None: + def build_from_single_year_dataset(self, dataset: UKSingleYearDataset) -> None: """Build simulation from a single-year UK dataset. Args: @@ -425,9 +409,7 @@ def build_from_single_year_dataset( self.build_from_multi_year_dataset(dataset) self.dataset = dataset - def build_from_multi_year_dataset( - self, dataset: UKMultiYearDataset - ) -> None: + def build_from_multi_year_dataset(self, dataset: UKMultiYearDataset) -> None: """Build simulation from a multi-year UK dataset. Args: @@ -592,9 +574,7 @@ def get_variable_dependencies(self, variable_name: str, depth: int = 1): trace=True, ) self._example_simulation.calculate("hbai_household_net_income") - for ( - variable - ) in self._example_simulation.tax_benefit_system.variables: + for variable in self._example_simulation.tax_benefit_system.variables: try: dependencies = get_variable_dependencies( variable, self._example_simulation @@ -615,9 +595,7 @@ def get_variable_dependencies(self, variable_name: str, depth: int = 1): all_dependencies = set(dependencies) for dep in dependencies: try: - sub_dependencies = self.get_variable_dependencies( - dep, depth - 1 - ) + sub_dependencies = self.get_variable_dependencies(dep, depth - 1) all_dependencies.update(sub_dependencies) except ValueError: continue @@ -648,13 +626,9 @@ def compare( df_self = self.calculate_dataframe(variables, period=period) df_other = other.calculate_dataframe(variables, period=period) - df_combined = pd.concat( - [df_self, df_other], axis=1, keys=["self", "other"] - ) + df_combined = pd.concat([df_self, df_other], axis=1, keys=["self", "other"]) # Reset columns, then order by variable name first then self/other - df_combined.columns = [ - f"{var}_{entity}" for entity, var in df_combined.columns - ] + df_combined.columns = [f"{var}_{entity}" for entity, var in df_combined.columns] # Add change where applicable (numeric only) for variable in variables: self_col = f"{variable}_self" diff --git a/policyengine_uk/tax_benefit_system.py b/policyengine_uk/tax_benefit_system.py index 9f117f5e2..6cb0b7919 100644 --- a/policyengine_uk/tax_benefit_system.py +++ b/policyengine_uk/tax_benefit_system.py @@ -101,9 +101,7 @@ def process_parameters(self) -> None: self.parameters = propagate_parameter_metadata(self.parameters) self.parameters = uprate_parameters(self.parameters) self.parameters = backdate_parameters(self.parameters, "2015-01-01") - self.parameters.gov = convert_to_fiscal_year_parameters( - self.parameters.gov - ) + self.parameters.gov = convert_to_fiscal_year_parameters(self.parameters.gov) self.reset_parameter_caches() def __init__(self): diff --git a/policyengine_uk/tests/microsimulation/test_reform_impacts.py b/policyengine_uk/tests/microsimulation/test_reform_impacts.py index 24cfde006..26561414f 100644 --- a/policyengine_uk/tests/microsimulation/test_reform_impacts.py +++ b/policyengine_uk/tests/microsimulation/test_reform_impacts.py @@ -58,9 +58,9 @@ def test_reform_fiscal_impacts(baseline, reform, reform_name, expected_impact): impact = get_fiscal_impact(baseline, reform) # Allow for small numerical differences (1 billion tolerance) - assert ( - abs(impact - expected_impact) < 1.0 - ), f"Impact for {reform_name} is {impact:.1f} billion, expected {expected_impact:.1f} billion" + assert abs(impact - expected_impact) < 1.0, ( + f"Impact for {reform_name} is {impact:.1f} billion, expected {expected_impact:.1f} billion" + ) def test_config_file_exists(): @@ -76,11 +76,9 @@ def test_all_reforms_have_required_fields(): for i, reform in enumerate(reforms_data): for field in required_fields: - assert ( - field in reform - ), f"Reform {i} missing required field: {field}" + assert field in reform, f"Reform {i} missing required field: {field}" - assert isinstance( - reform["parameters"], dict - ), f"Reform {i} parameters must be a dictionary" + assert isinstance(reform["parameters"], dict), ( + f"Reform {i} parameters must be a dictionary" + ) assert len(reform["parameters"]) > 0, f"Reform {i} has no parameters" diff --git a/policyengine_uk/tests/microsimulation/test_salary_sacrifice_cap_reform.py b/policyengine_uk/tests/microsimulation/test_salary_sacrifice_cap_reform.py index 81ab412c9..74d9c2a75 100644 --- a/policyengine_uk/tests/microsimulation/test_salary_sacrifice_cap_reform.py +++ b/policyengine_uk/tests/microsimulation/test_salary_sacrifice_cap_reform.py @@ -26,9 +26,7 @@ # Expected revenue impact in billions (from current model run) # Original blog estimate: £3.3 billion; updated to reflect current model. EXPECTED_REVENUE_BILLION = 1.8 -TOLERANCE_BILLION = ( - 1.0 # Allow reasonable tolerance for year/methodology differences -) +TOLERANCE_BILLION = 1.0 # Allow reasonable tolerance for year/methodology differences def _create_no_cap_baseline(): @@ -58,9 +56,7 @@ def reform_simulation(): @pytest.mark.microsimulation -def test_salary_sacrifice_cap_revenue_impact( - baseline_simulation, reform_simulation -): +def test_salary_sacrifice_cap_revenue_impact(baseline_simulation, reform_simulation): """ Test that the £2,000 salary sacrifice cap raises ~£3.3 billion. @@ -72,14 +68,12 @@ def test_salary_sacrifice_cap_revenue_impact( baseline_gov_balance = baseline_simulation.calculate( "gov_balance", POLICY_YEAR ).sum() - reform_gov_balance = reform_simulation.calculate( - "gov_balance", POLICY_YEAR - ).sum() + reform_gov_balance = reform_simulation.calculate("gov_balance", POLICY_YEAR).sum() revenue_impact_billion = (reform_gov_balance - baseline_gov_balance) / 1e9 - print(f"\nBaseline gov_balance: £{baseline_gov_balance/1e9:.3f} billion") - print(f"Reform gov_balance: £{reform_gov_balance/1e9:.3f} billion") + print(f"\nBaseline gov_balance: £{baseline_gov_balance / 1e9:.3f} billion") + print(f"Reform gov_balance: £{reform_gov_balance / 1e9:.3f} billion") print(f"Revenue impact: £{revenue_impact_billion:.3f} billion") # The reform should raise revenue (positive impact) @@ -89,10 +83,7 @@ def test_salary_sacrifice_cap_revenue_impact( ) # Revenue should be approximately £3.3 billion - assert ( - abs(revenue_impact_billion - EXPECTED_REVENUE_BILLION) - < TOLERANCE_BILLION - ), ( + assert abs(revenue_impact_billion - EXPECTED_REVENUE_BILLION) < TOLERANCE_BILLION, ( f"Salary sacrifice cap revenue is {revenue_impact_billion:.2f} billion, " f"expected ~{EXPECTED_REVENUE_BILLION:.1f} billion " f"(±{TOLERANCE_BILLION:.1f} billion tolerance)" @@ -116,19 +107,19 @@ def test_ni_increases_with_reform(baseline_simulation, reform_simulation): ni_increase = reform_ni - baseline_ni - print(f"\nBaseline NI: £{baseline_ni/1e9:.3f}bn") - print(f"Reform NI: £{reform_ni/1e9:.3f}bn") - print(f"NI increase: £{ni_increase/1e9:.3f}bn") + print(f"\nBaseline NI: £{baseline_ni / 1e9:.3f}bn") + print(f"Reform NI: £{reform_ni / 1e9:.3f}bn") + print(f"NI increase: £{ni_increase / 1e9:.3f}bn") # NI should increase with the reform - assert ( - ni_increase > 0 - ), f"NI should increase with cap, but change is £{ni_increase/1e9:.3f}bn" + assert ni_increase > 0, ( + f"NI should increase with cap, but change is £{ni_increase / 1e9:.3f}bn" + ) # NI increase should be significant (at least £1bn) - assert ( - ni_increase > 1e9 - ), f"NI increase should be >£1bn, got £{ni_increase/1e9:.3f}bn" + assert ni_increase > 1e9, ( + f"NI increase should be >£1bn, got £{ni_increase / 1e9:.3f}bn" + ) @pytest.mark.microsimulation @@ -140,25 +131,23 @@ def test_income_tax_impact(baseline_simulation, reform_simulation): contributions for relief. Due to pension relief caps, some people don't get full relief, resulting in a small positive income tax impact. """ - baseline_tax = baseline_simulation.calculate( - "income_tax", POLICY_YEAR - ).sum() + baseline_tax = baseline_simulation.calculate("income_tax", POLICY_YEAR).sum() reform_tax = reform_simulation.calculate("income_tax", POLICY_YEAR).sum() tax_change = reform_tax - baseline_tax - print(f"\nBaseline income tax: £{baseline_tax/1e9:.3f}bn") - print(f"Reform income tax: £{reform_tax/1e9:.3f}bn") - print(f"Income tax change: £{tax_change/1e9:.3f}bn") + print(f"\nBaseline income tax: £{baseline_tax / 1e9:.3f}bn") + print(f"Reform income tax: £{reform_tax / 1e9:.3f}bn") + print(f"Income tax change: £{tax_change / 1e9:.3f}bn") # Income tax change should be small and approximately neutral. # The reform redirects excess salary sacrifice to employee pension # contributions (which get income tax relief), while the total pension # input for Annual Allowance purposes stays the same (no AA charge # difference). Net effect is a small income tax decrease. - assert ( - abs(tax_change) < 1e9 - ), f"Income tax change should be small (<£1bn), got £{tax_change/1e9:.3f}bn" + assert abs(tax_change) < 1e9, ( + f"Income tax change should be small (<£1bn), got £{tax_change / 1e9:.3f}bn" + ) @pytest.mark.microsimulation @@ -174,9 +163,9 @@ def test_excess_redirected_to_pension(reform_simulation): ).sum() # Should be significant (blog says £13.8bn excess - updated to current model) - assert ( - redirected > 8e9 - ), f"Redirected amount should be >£8bn, got £{redirected/1e9:.2f}bn" + assert redirected > 8e9, ( + f"Redirected amount should be >£8bn, got £{redirected / 1e9:.2f}bn" + ) @pytest.mark.microsimulation @@ -194,12 +183,12 @@ def test_salary_sacrifice_data_exists(reform_simulation): num_contributors = (ss_contributions > 0).sum() # Should have significant SS contributions - assert ( - total_ss > 20e9 - ), f"Total SS contributions should be >£20bn, got £{total_ss/1e9:.2f}bn" - assert ( - num_contributors > 4e6 - ), f"Should have >4 million contributors, got {num_contributors/1e6:.1f}m" + assert total_ss > 20e9, ( + f"Total SS contributions should be >£20bn, got £{total_ss / 1e9:.2f}bn" + ) + assert num_contributors > 4e6, ( + f"Should have >4 million contributors, got {num_contributors / 1e6:.1f}m" + ) @pytest.mark.microsimulation @@ -217,12 +206,12 @@ def test_affected_population(reform_simulation): affected_count = (ss_contributions > cap).sum() # Should be around 3.3 million - assert ( - affected_count > 2.5e6 - ), f"Expected >2.5 million affected, got {affected_count/1e6:.1f}m" - assert ( - affected_count < 5e6 - ), f"Expected <5 million affected, got {affected_count/1e6:.1f}m" + assert affected_count > 2.5e6, ( + f"Expected >2.5 million affected, got {affected_count / 1e6:.1f}m" + ) + assert affected_count < 5e6, ( + f"Expected <5 million affected, got {affected_count / 1e6:.1f}m" + ) @pytest.mark.microsimulation @@ -253,8 +242,8 @@ def test_full_excess_redirected(reform_simulation): assert 0.95 < ratio < 1.05, ( f"Full excess should be redirected (ratio ~1.0). " - f"Raw excess: £{raw_excess/1e9:.2f}bn, " - f"Redirected: £{redirected_total/1e9:.2f}bn, " + f"Raw excess: £{raw_excess / 1e9:.2f}bn, " + f"Redirected: £{redirected_total / 1e9:.2f}bn, " f"Ratio: {ratio:.2f}" ) @@ -283,10 +272,8 @@ def test_broad_base_haircut_affects_all_workers(reform_simulation): workers_with_employment = (has_employment * weights).sum() workers_with_haircut = (has_haircut * weights).sum() - print( - f"\nWorkers with employment income: {workers_with_employment/1e6:.1f}m" - ) - print(f"Workers with haircut: {workers_with_haircut/1e6:.1f}m") + print(f"\nWorkers with employment income: {workers_with_employment / 1e6:.1f}m") + print(f"Workers with haircut: {workers_with_haircut / 1e6:.1f}m") # Most workers with employment income should have a haircut haircut_coverage = workers_with_haircut / workers_with_employment @@ -352,16 +339,13 @@ def test_decile_impact_negative_for_higher_earners( results = [] for decile_num in range(1, 11): - decile_data = decile_df[ - decile_df["household_income_decile"] == decile_num - ] + decile_data = decile_df[decile_df["household_income_decile"] == decile_num] if len(decile_data) > 0: weighted_change = ( decile_data["income_change"] * decile_data["household_weight"] ).sum() weighted_baseline = ( - decile_data["baseline_income"] - * decile_data["household_weight"] + decile_data["baseline_income"] * decile_data["household_weight"] ).sum() rel_change = ( (weighted_change / weighted_baseline) * 100 @@ -400,8 +384,8 @@ def test_decile_impact_negative_for_higher_earners( # Overall impact should be negative (reform takes money from households) total_change = sum(r["abs_change"] for r in results) - print(f"\nTotal household income change: £{total_change/1e9:.3f}bn") + print(f"\nTotal household income change: £{total_change / 1e9:.3f}bn") assert total_change < 0, ( f"Total household income should decrease, " - f"got £{total_change/1e9:.3f}bn change" + f"got £{total_change / 1e9:.3f}bn change" ) diff --git a/policyengine_uk/tests/microsimulation/update_reform_impacts.py b/policyengine_uk/tests/microsimulation/update_reform_impacts.py index 70bf7e7a9..5095b4034 100644 --- a/policyengine_uk/tests/microsimulation/update_reform_impacts.py +++ b/policyengine_uk/tests/microsimulation/update_reform_impacts.py @@ -41,9 +41,7 @@ def get_fiscal_impact(reform: dict) -> float: return float((reform_revenue - baseline_revenue) / 1e9) -def update_impacts( - config_path: Path, dry_run: bool = False, verbose: bool = True -): +def update_impacts(config_path: Path, dry_run: bool = False, verbose: bool = True): """ Update the expected impacts in the configuration file with current model values. @@ -89,9 +87,7 @@ def update_impacts( old_impact = reform["expected_impact"] new_impact = round(get_fiscal_impact(reform["parameters"]), 1) - if ( - abs(old_impact - new_impact) > 0.01 - ): # Only record meaningful changes + if abs(old_impact - new_impact) > 0.01: # Only record meaningful changes changes.append( { "name": reform["name"], @@ -138,9 +134,7 @@ def update_impacts( ) console.print("\n", table) - console.print( - f"\n[bold cyan]Total changes: {len(changes)}[/bold cyan]" - ) + console.print(f"\n[bold cyan]Total changes: {len(changes)}[/bold cyan]") else: console.print("\n[green]✓ No significant changes detected.[/green]") @@ -170,9 +164,7 @@ def update_impacts( ) ) else: - console.print( - "\n[yellow]⚠ Dry run - no changes written to file.[/yellow]" - ) + console.print("\n[yellow]⚠ Dry run - no changes written to file.[/yellow]") def main(): @@ -183,9 +175,7 @@ def main(): parser.add_argument( "--config", type=Path, - default=Path( - "policyengine_uk/tests/microsimulation/reforms_config.yaml" - ), + default=Path("policyengine_uk/tests/microsimulation/reforms_config.yaml"), help="Path to the reforms configuration file (default: reforms_config.yaml)", ) parser.add_argument( diff --git a/policyengine_uk/tests/test_behavioral_responses.py b/policyengine_uk/tests/test_behavioral_responses.py index e877a7e19..9dd869cc0 100644 --- a/policyengine_uk/tests/test_behavioral_responses.py +++ b/policyengine_uk/tests/test_behavioral_responses.py @@ -26,9 +26,7 @@ # Load YAML test cases yaml_file = ( - Path(__file__).parent - / "behavioral_responses" - / "test_labor_supply_responses.yaml" + Path(__file__).parent / "behavioral_responses" / "test_labor_supply_responses.yaml" ) with open(yaml_file, "r") as f: yaml_content = f.read() @@ -40,16 +38,14 @@ class TestBehavioralResponses: def test_yaml_file_structure(self): """Test that YAML file loads correctly and has expected structure""" - assert ( - len(test_cases) == 6 - ), f"Expected 6 test cases, got {len(test_cases)}" + assert len(test_cases) == 6, f"Expected 6 test cases, got {len(test_cases)}" for i, test_case in enumerate(test_cases): - assert "name" in test_case, f"Test case {i+1} missing 'name'" - assert "period" in test_case, f"Test case {i+1} missing 'period'" - assert "input" in test_case, f"Test case {i+1} missing 'input'" - assert "reforms" in test_case, f"Test case {i+1} missing 'reforms'" - assert "output" in test_case, f"Test case {i+1} missing 'output'" + assert "name" in test_case, f"Test case {i + 1} missing 'name'" + assert "period" in test_case, f"Test case {i + 1} missing 'period'" + assert "input" in test_case, f"Test case {i + 1} missing 'input'" + assert "reforms" in test_case, f"Test case {i + 1} missing 'reforms'" + assert "output" in test_case, f"Test case {i + 1} missing 'output'" @requires_hf_data def test_obr_parameter_functionality(self): @@ -76,12 +72,8 @@ def test_obr_parameter_functionality(self): "2025" ) - assert ( - obr_on == True - ), "OBR parameter should be enabled when set to True" - assert ( - obr_off == False - ), "OBR parameter should be disabled when set to False" + assert obr_on == True, "OBR parameter should be enabled when set to True" + assert obr_off == False, "OBR parameter should be disabled when set to False" @requires_hf_data def test_dynamics_no_crash_simple(self): @@ -109,13 +101,12 @@ def test_dynamics_no_crash_simple(self): dynamics = reformed.apply_dynamics(2025) # If successful, dynamics may be None if no income change if dynamics is not None: - assert hasattr( - dynamics, "fte_impacts" - ), "Dynamics should have fte_impacts attribute" + assert hasattr(dynamics, "fte_impacts"), ( + "Dynamics should have fte_impacts attribute" + ) except ValueError as e: if ( - "Bin labels must be one fewer than the number of bin edges" - in str(e) + "Bin labels must be one fewer than the number of bin edges" in str(e) ) or ("assignment destination is read-only" in str(e)): # Bin edge error: expected with single-person scenarios # Read-only error: pandas 3.x copy-on-write; fix pending in core @@ -220,17 +211,15 @@ def test_all_yaml_cases_structure(self, test_case): reformed = Microsimulation(situation=situation) # Basic validation - should have people - assert ( - len(situation["people"]) > 0 - ), f"Test case '{test_case['name']}' should have people" + assert len(situation["people"]) > 0, ( + f"Test case '{test_case['name']}' should have people" + ) # Should be able to calculate basic variables - employment_income = reformed.calculate( - "employment_income", test_case["period"] + employment_income = reformed.calculate("employment_income", test_case["period"]) + assert employment_income is not None, ( + f"Should be able to calculate employment_income for '{test_case['name']}'" ) - assert ( - employment_income is not None - ), f"Should be able to calculate employment_income for '{test_case['name']}'" if __name__ == "__main__": diff --git a/policyengine_uk/tests/test_deterministic_variables.py b/policyengine_uk/tests/test_deterministic_variables.py index 0d0889b91..b76de48ad 100644 --- a/policyengine_uk/tests/test_deterministic_variables.py +++ b/policyengine_uk/tests/test_deterministic_variables.py @@ -172,9 +172,7 @@ def test_higher_income_wins(self): }, }, "benunits": {"benunit": {"members": ["person1", "person2"]}}, - "households": { - "household": {"members": ["person1", "person2"]} - }, + "households": {"household": {"members": ["person1", "person2"]}}, } ) result = sim.calculate("is_higher_earner", 2024) @@ -198,9 +196,7 @@ def test_same_income_older_wins(self): }, }, "benunits": {"benunit": {"members": ["person1", "person2"]}}, - "households": { - "household": {"members": ["person1", "person2"]} - }, + "households": {"household": {"members": ["person1", "person2"]}}, } ) result = sim.calculate("is_higher_earner", 2024) diff --git a/policyengine_uk/tests/test_fiscal_year_parameters.py b/policyengine_uk/tests/test_fiscal_year_parameters.py index 1211e0286..08992a266 100644 --- a/policyengine_uk/tests/test_fiscal_year_parameters.py +++ b/policyengine_uk/tests/test_fiscal_year_parameters.py @@ -29,9 +29,7 @@ class TestTwoChildLimitRepeal: def test_two_child_limit_fiscal_year_2025(self, uk_system): """Test that the two-child limit is 2 for fiscal year 2025/26.""" params = uk_system.get_parameters_at_instant("2025") - child_limit = ( - params.gov.dwp.universal_credit.elements.child.limit.child_count - ) + child_limit = params.gov.dwp.universal_credit.elements.child.limit.child_count assert child_limit == 2 def test_two_child_limit_fiscal_year_2026(self, uk_system): @@ -42,9 +40,7 @@ def test_two_child_limit_fiscal_year_2026(self, uk_system): as the reference date, which is AFTER the repeal date. """ params = uk_system.get_parameters_at_instant("2026") - child_limit = ( - params.gov.dwp.universal_credit.elements.child.limit.child_count - ) + child_limit = params.gov.dwp.universal_credit.elements.child.limit.child_count assert child_limit == float("inf"), ( f"Expected infinity for 2026 fiscal year, got {child_limit}. " "The fiscal year conversion may not be covering 2026." @@ -94,18 +90,14 @@ def test_january_2026_returns_fiscal_year_2026_value(self, uk_system): April 30, 2026 value (infinity, post-repeal). """ params = uk_system.get_parameters_at_instant("2026-01-15") - child_limit = ( - params.gov.dwp.universal_credit.elements.child.limit.child_count - ) + child_limit = params.gov.dwp.universal_credit.elements.child.limit.child_count # This returns inf because the whole year 2026 is set to fiscal year value assert child_limit == float("inf") def test_december_2025_returns_fiscal_year_2025_value(self, uk_system): """December 2025 should return fiscal year 2025/26 value.""" params = uk_system.get_parameters_at_instant("2025-12-15") - child_limit = ( - params.gov.dwp.universal_credit.elements.child.limit.child_count - ) + child_limit = params.gov.dwp.universal_credit.elements.child.limit.child_count # The year 2025 is set to April 30, 2025 value (2, pre-repeal) assert child_limit == 2 @@ -113,9 +105,7 @@ def test_december_2025_returns_fiscal_year_2025_value(self, uk_system): class TestFiscalYearCoverage: """Tests to verify fiscal year conversion covers all needed years.""" - @pytest.mark.parametrize( - "year", [2025, 2026, 2027, 2028, 2029, 2030, 2040] - ) + @pytest.mark.parametrize("year", [2025, 2026, 2027, 2028, 2029, 2030, 2040]) def test_year_in_conversion_range(self, uk_system, year): """ Test that years from 2025-2040 can be queried. diff --git a/policyengine_uk/utils/compare.py b/policyengine_uk/utils/compare.py index 8d7073d31..e883e4bc2 100644 --- a/policyengine_uk/utils/compare.py +++ b/policyengine_uk/utils/compare.py @@ -12,9 +12,7 @@ def compare_simulations( variables: list[str], ): dfs = [ - sim.calculate_dataframe(variables, year).rename( - columns=lambda x: f"{x}_{name}" - ) + sim.calculate_dataframe(variables, year).rename(columns=lambda x: f"{x}_{name}") for sim, name in zip(simulations, names) ] diff --git a/policyengine_uk/utils/create_ahc_deflator.py b/policyengine_uk/utils/create_ahc_deflator.py index 336f7cd8c..0d0e90df3 100644 --- a/policyengine_uk/utils/create_ahc_deflator.py +++ b/policyengine_uk/utils/create_ahc_deflator.py @@ -19,12 +19,8 @@ "w_repair": 2.9902 / 1000, } -cpi = ( - system.parameters.gov.economic_assumptions.indices.obr.consumer_price_index -) -water_index = ( - system.parameters.gov.economic_assumptions.indices.ofwat.water_bills -) +cpi = system.parameters.gov.economic_assumptions.indices.obr.consumer_price_index +water_index = system.parameters.gov.economic_assumptions.indices.ofwat.water_bills rent_index = system.parameters.gov.economic_assumptions.indices.obr.rent @@ -104,9 +100,7 @@ def create_modified_cpi_forecast( + current_weights["w_rent"] * pi_rent ) - pi_other = (pi_total - housing_contribution) / current_weights[ - "w_other" - ] + pi_other = (pi_total - housing_contribution) / current_weights["w_other"] new_modified_index = last_modified_index * (1 + pi_other) @@ -146,9 +140,7 @@ def create_modified_cpi_forecast( current_weights["w_rent"] * (1 + pi_rent) / total_weighted_growth ) current_weights["w_repair"] = ( - current_weights["w_repair"] - * (1 + pi_repair) - / total_weighted_growth + current_weights["w_repair"] * (1 + pi_repair) / total_weighted_growth ) current_weights["w_other"] = ( current_weights["w_other"] * (1 + pi_other) / total_weighted_growth diff --git a/policyengine_uk/utils/create_triple_lock.py b/policyengine_uk/utils/create_triple_lock.py index 4bb61f75b..b4af9b8c6 100644 --- a/policyengine_uk/utils/create_triple_lock.py +++ b/policyengine_uk/utils/create_triple_lock.py @@ -2,9 +2,7 @@ # Run this script to generate the triple lock parameter for updated CPI and average earnings forecasts from the OBR. -cpi = ( - system.parameters.gov.economic_assumptions.indices.obr.consumer_price_index -) +cpi = system.parameters.gov.economic_assumptions.indices.obr.consumer_price_index average_earnings = ( system.parameters.gov.economic_assumptions.indices.obr.average_earnings ) diff --git a/policyengine_uk/utils/dependencies.py b/policyengine_uk/utils/dependencies.py index 71f4126d3..1d433d969 100644 --- a/policyengine_uk/utils/dependencies.py +++ b/policyengine_uk/utils/dependencies.py @@ -52,9 +52,7 @@ def calculate_dependency_contributions( original_values = sim.calculate(variable_name, year) if map_to is not None: - source_entity = sim.tax_benefit_system.get_variable( - variable_name - ).entity.key + source_entity = sim.tax_benefit_system.get_variable(variable_name).entity.key original_values_mapped = sim.map_result( original_values, source_entity, @@ -127,9 +125,7 @@ def create_waterfall_chart(sim, variable_name, year, top_n=5): "Simulation must have trace enabled to create a waterfall chart." ) - df = calculate_dependency_contributions( - sim, variable_name, year, top_n=top_n - ) + df = calculate_dependency_contributions(sim, variable_name, year, top_n=top_n) # make a waterfall chart diff --git a/policyengine_uk/utils/parameters.py b/policyengine_uk/utils/parameters.py index fc07bb797..8eb08a2b0 100644 --- a/policyengine_uk/utils/parameters.py +++ b/policyengine_uk/utils/parameters.py @@ -6,9 +6,7 @@ def str_to_instant(s): return periods.Instant(tuple(map(lambda s: int(s), s.split("-")))) -def backdate_parameters( - root: str = None, first_instant: str = "2021-01-01" -) -> Reform: +def backdate_parameters(root: str = None, first_instant: str = "2021-01-01") -> Reform: first_instant = str_to_instant(first_instant) node = root for param in node.get_descendants(): diff --git a/policyengine_uk/utils/scenario.py b/policyengine_uk/utils/scenario.py index 608d7b42f..d251699af 100644 --- a/policyengine_uk/utils/scenario.py +++ b/policyengine_uk/utils/scenario.py @@ -85,9 +85,7 @@ def combined_modifier(simulation: Simulation) -> None: ) @classmethod - def from_reform( - cls, reform: Union[tuple, dict, Type[Reform]] - ) -> "Scenario": + def from_reform(cls, reform: Union[tuple, dict, Type[Reform]]) -> "Scenario": """Create a Scenario from various reform representations. Args: @@ -141,9 +139,7 @@ def modifier(sim: Simulation): stop = None period_ = None - sim.tax_benefit_system.parameters.get_child( - parameter - ).update( + sim.tax_benefit_system.parameters.get_child(parameter).update( start=start, stop=stop, period=period_, @@ -217,9 +213,7 @@ def __repr__(self) -> str: """String representation of the Scenario.""" parts = [] if self.parameter_changes: - parts.append( - f"parameter_changes={len(self.parameter_changes)} items" - ) + parts.append(f"parameter_changes={len(self.parameter_changes)} items") if self.simulation_modifier: parts.append("simulation_modifier=") return f"Scenario({', '.join(parts)})" diff --git a/policyengine_uk/utils/solve_private_school_attendance_factor.py b/policyengine_uk/utils/solve_private_school_attendance_factor.py index 76da52656..47923382d 100644 --- a/policyengine_uk/utils/solve_private_school_attendance_factor.py +++ b/policyengine_uk/utils/solve_private_school_attendance_factor.py @@ -10,9 +10,7 @@ for factor in tqdm([round(x * 0.01, 2) for x in range(70, 91)]): # Define the reform with the current private_school_factor value reform = { - "gov.contrib.labour.private_school_vat": { - "2024-01-01.2100-12-31": 0.2 - }, + "gov.contrib.labour.private_school_vat": {"2024-01-01.2100-12-31": 0.2}, "gov.simulation.private_school_vat.private_school_factor": { "2024-01-01.2100-12-31": factor }, @@ -22,9 +20,7 @@ reformed = Microsimulation( reform=reform, ) - reformed.baseline_simulation.get_holder( - "attends_private_school" - ).delete_arrays() + reformed.baseline_simulation.get_holder("attends_private_school").delete_arrays() # Calculate the number of students attending private school in thousands private_school_attendance = ( diff --git a/policyengine_uk/utils/water/forecast_water_bills.py b/policyengine_uk/utils/water/forecast_water_bills.py index 46e9d833f..52ed47a97 100644 --- a/policyengine_uk/utils/water/forecast_water_bills.py +++ b/policyengine_uk/utils/water/forecast_water_bills.py @@ -24,12 +24,8 @@ def project_water_bills(): df_pre_2025["Oftwat avg bills (nominal)"].pct_change() * 100 ).round(1) - proposed_increases = pd.read_csv( - Path(__file__).parent / "ofwat_increases.csv" - ) - proposed_increases = MicroDataFrame( - proposed_increases, weights="Customers" - ) + proposed_increases = pd.read_csv(Path(__file__).parent / "ofwat_increases.csv") + proposed_increases = MicroDataFrame(proposed_increases, weights="Customers") avg_bills_2025_onwards = ( proposed_increases[proposed_increases.columns[2:]].mean().values ) @@ -61,9 +57,9 @@ def project_water_bills(): df_post_2025["Year"] == year - 1, "Avg bills (nominal)" ].values[0] * (cpi_change / 100) # Add addition to this and future years - df_post_2025.loc[ - df_post_2025["Year"] >= year, "Avg bills (nominal)" - ] += addition + df_post_2025.loc[df_post_2025["Year"] >= year, "Avg bills (nominal)"] += ( + addition + ) df_post_2025["Relative change"] = ( df_post_2025["Avg bills (nominal)"].pct_change() * 100 diff --git a/policyengine_uk/variables/contrib/cec/non_primary_residence_wealth_tax.py b/policyengine_uk/variables/contrib/cec/non_primary_residence_wealth_tax.py index 1744b13f2..66d7b6dab 100644 --- a/policyengine_uk/variables/contrib/cec/non_primary_residence_wealth_tax.py +++ b/policyengine_uk/variables/contrib/cec/non_primary_residence_wealth_tax.py @@ -3,9 +3,7 @@ class non_primary_residence_wealth_tax(Variable): label = "Wealth tax (non-primary residence)" - documentation = ( - "Annual tax on household net wealth excluding primary residences" - ) + documentation = "Annual tax on household net wealth excluding primary residences" entity = Household definition_period = YEAR value_type = float @@ -14,7 +12,5 @@ class non_primary_residence_wealth_tax(Variable): def formula(household, period, parameters): wealth = household("total_wealth", period) primary_residence = household("main_residence_value", period) - tax = parameters( - period - ).gov.contrib.cec.non_primary_residence_wealth_tax + tax = parameters(period).gov.contrib.cec.non_primary_residence_wealth_tax return tax.calc(max_(0, wealth - primary_residence)) diff --git a/policyengine_uk/variables/contrib/labour/attends_private_school.py b/policyengine_uk/variables/contrib/labour/attends_private_school.py index f0307fd33..27cc135f6 100644 --- a/policyengine_uk/variables/contrib/labour/attends_private_school.py +++ b/policyengine_uk/variables/contrib/labour/attends_private_school.py @@ -42,9 +42,7 @@ def formula(person, period, parameters): # total number of students actually enrolled ps_vat_params = parameters(period).gov.simulation.private_school_vat - private_school_attendance_rate = ( - ps_vat_params.private_school_attendance_rate - ) + private_school_attendance_rate = ps_vat_params.private_school_attendance_rate population_adjustment_factor = ps_vat_params.private_school_factor @@ -85,10 +83,7 @@ def formula(person, period, parameters): # the full percentile array. Replaces ~115k Python calls with numpy ops. _breakpoints = list(range(0, 101, 5)) _rates = np.array( - [ - float(private_school_attendance_rate[str(p)]) - for p in _breakpoints - ] + [float(private_school_attendance_rate[str(p)]) for p in _breakpoints] ) _rate_by_percentile = np.interp(np.arange(101), _breakpoints, _rates) diff --git a/policyengine_uk/variables/contrib/policyengine/education_budget_change.py b/policyengine_uk/variables/contrib/policyengine/education_budget_change.py index 40dc89305..02257ec1c 100644 --- a/policyengine_uk/variables/contrib/policyengine/education_budget_change.py +++ b/policyengine_uk/variables/contrib/policyengine/education_budget_change.py @@ -13,9 +13,7 @@ def formula(household, period, parameters): ) if budget_increase == 0: return 0 - decile = household( - "pre_budget_change_ons_household_income_decile", period - ) + decile = household("pre_budget_change_ons_household_income_decile", period) weight = household("household_weight", period) DECILE_INCIDENCE = { 1: 0.114, @@ -35,9 +33,7 @@ def formula(household, period, parameters): i: budget_increase * DECILE_INCIDENCE[i] for i in range(1, 11) } if household.simulation.dataset is not None: - households_per_decile = ( - pd.Series(weight).groupby(decile).sum().to_dict() - ) + households_per_decile = pd.Series(weight).groupby(decile).sum().to_dict() else: households_per_decile = {i: 28e5 for i in range(1, 11)} diff --git a/policyengine_uk/variables/contrib/policyengine/employer_ni/adjusted_employer_cost.py b/policyengine_uk/variables/contrib/policyengine/employer_ni/adjusted_employer_cost.py index e776990f3..863a35adf 100644 --- a/policyengine_uk/variables/contrib/policyengine/employer_ni/adjusted_employer_cost.py +++ b/policyengine_uk/variables/contrib/policyengine/employer_ni/adjusted_employer_cost.py @@ -31,16 +31,12 @@ def formula(person, period, parameters): class_1 = parameters.gov.hmrc.national_insurance.class_1 r_r = class_1.rates.employer t_r = class_1.thresholds.secondary_threshold * WEEKS_IN_YEAR - p_r = ( - parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions - ) + p_r = parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions pen_con_subtracted_r = employer_pension_contributions if p_r: pen_con_subtracted_r = employer_pension_contributions else: pen_con_subtracted_r = 0 - employer_ni = r_r * max_( - 0, ni_class_1_income - pen_con_subtracted_r - t_r - ) + employer_ni = r_r * max_(0, ni_class_1_income - pen_con_subtracted_r - t_r) return ni_class_1_income + employer_ni diff --git a/policyengine_uk/variables/contrib/policyengine/employer_ni/baseline_employer_cost.py b/policyengine_uk/variables/contrib/policyengine/employer_ni/baseline_employer_cost.py index 0a32170c4..3f32b7291 100644 --- a/policyengine_uk/variables/contrib/policyengine/employer_ni/baseline_employer_cost.py +++ b/policyengine_uk/variables/contrib/policyengine/employer_ni/baseline_employer_cost.py @@ -9,9 +9,7 @@ class baseline_employer_cost(Variable): unit = GBP def formula(person, period, parameters): - prior_employment_income = person( - "employment_income_before_lsr", period - ) + prior_employment_income = person("employment_income_before_lsr", period) employment_income_behavioral_response = person( "employment_income_behavioral_response", period ) @@ -37,17 +35,13 @@ def formula(person, period, parameters): # Calculate baseline employer cost if person.simulation.baseline is None: return 0 - baseline_parameters = ( - person.simulation.baseline.tax_benefit_system.parameters(period) - ) - baseline_class_1 = ( - baseline_parameters.gov.hmrc.national_insurance.class_1 + baseline_parameters = person.simulation.baseline.tax_benefit_system.parameters( + period ) + baseline_class_1 = baseline_parameters.gov.hmrc.national_insurance.class_1 r_b = baseline_class_1.rates.employer t_b = baseline_class_1.thresholds.secondary_threshold * WEEKS_IN_YEAR - p_b = ( - baseline_parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions - ) + p_b = baseline_parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions pen_con_subtracted_b = employer_pension_contributions if p_b: pen_con_subtracted_b = employer_pension_contributions diff --git a/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_fixed_employer_cost_change.py b/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_fixed_employer_cost_change.py index 151fd093f..be4aa1706 100644 --- a/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_fixed_employer_cost_change.py +++ b/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_fixed_employer_cost_change.py @@ -16,9 +16,7 @@ def formula(person, period, parameters): return 0 # First, calculate baseline and reformed employer NI contributions. - prior_employment_income = person( - "employment_income_before_lsr", period - ) + prior_employment_income = person("employment_income_before_lsr", period) employment_income_behavioral_response = person( "employment_income_behavioral_response", period ) @@ -44,18 +42,14 @@ def formula(person, period, parameters): # Calculate baseline employer cost if person.simulation.baseline is None: return 0 - baseline_parameters = ( - person.simulation.baseline.tax_benefit_system.parameters(period) + baseline_parameters = person.simulation.baseline.tax_benefit_system.parameters( + period ) - baseline_class_1 = ( - baseline_parameters.gov.hmrc.national_insurance.class_1 - ) + baseline_class_1 = baseline_parameters.gov.hmrc.national_insurance.class_1 r_b = baseline_class_1.rates.employer t_b = baseline_class_1.thresholds.secondary_threshold * WEEKS_IN_YEAR - p_b = ( - baseline_parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions - ) + p_b = baseline_parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions pen_con_subtracted_b = employer_pension_contributions if p_b else 0 baseline_employer_ni = r_b * max_( @@ -68,9 +62,7 @@ def formula(person, period, parameters): reform_class_1 = reform_parameters.gov.hmrc.national_insurance.class_1 r_r = reform_class_1.rates.employer t_r = reform_class_1.thresholds.secondary_threshold * WEEKS_IN_YEAR - p_r = ( - reform_parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions - ) + p_r = reform_parameters.gov.contrib.policyengine.employer_ni.exempt_employer_pension_contributions pen_con_subtracted_r = employer_pension_contributions if p_r else 0 # Early return if no change in parameters @@ -80,9 +72,7 @@ def formula(person, period, parameters): # Calculate new employment income keeping employer cost constant # Solve: c_b = new_ni_class_1_income + r_r * max(new_ni_class_1_income - pen_con_subtracted_r - t_r, 0) # Rearranging: new_ni_class_1_income = (c_b + r_r * (pen_con_subtracted_r + t_r)) / (1 + r_r) - new_ni_class_1_income = (c_b + r_r * (pen_con_subtracted_r + t_r)) / ( - 1 + r_r - ) + new_ni_class_1_income = (c_b + r_r * (pen_con_subtracted_r + t_r)) / (1 + r_r) # Find difference in employment income previous_employment_income = ( diff --git a/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_capital_incidence.py b/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_capital_incidence.py index 31f284869..cd29a8de2 100644 --- a/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_capital_incidence.py +++ b/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_capital_incidence.py @@ -22,21 +22,16 @@ def formula(person, period, parameters): baseline_employer_cost = person("baseline_employer_cost", period) employer_cost = person("adjusted_employer_cost", period) change_in_employer_cost = employer_cost - baseline_employer_cost - amount_paid_by_employers = ( - person_weight * change_in_employer_cost - ).sum() + amount_paid_by_employers = (person_weight * change_in_employer_cost).sum() wealth = ( - person.household("corporate_wealth", period) - / person.household.nb_persons() + person.household("corporate_wealth", period) / person.household.nb_persons() ) total_wealth = (wealth * person_weight).sum() share_of_total_wealth = wealth / total_wealth value = ( - amount_paid_by_employers - * share_of_total_wealth - * emp_ni.capital_incidence + amount_paid_by_employers * share_of_total_wealth * emp_ni.capital_incidence ) if total_wealth == 0: diff --git a/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_consumer_incidence.py b/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_consumer_incidence.py index 1e48f626f..629de60fc 100644 --- a/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_consumer_incidence.py +++ b/policyengine_uk/variables/contrib/policyengine/employer_ni/employer_ni_response_consumer_incidence.py @@ -22,13 +22,10 @@ def formula(person, period, parameters): baseline_employer_cost = person("baseline_employer_cost", period) employer_cost = person("adjusted_employer_cost", period) change_in_employer_cost = employer_cost - baseline_employer_cost - amount_paid_by_employers = ( - person_weight * change_in_employer_cost - ).sum() + amount_paid_by_employers = (person_weight * change_in_employer_cost).sum() consumption = ( - person.household("consumption", period) - / person.household.nb_persons() + person.household("consumption", period) / person.household.nb_persons() ) total_consumption = (consumption * person_weight).sum() share_of_total_consumption = consumption / total_consumption diff --git a/policyengine_uk/variables/contrib/policyengine/nhs_budget_change.py b/policyengine_uk/variables/contrib/policyengine/nhs_budget_change.py index 7899add8a..a7b3ac347 100644 --- a/policyengine_uk/variables/contrib/policyengine/nhs_budget_change.py +++ b/policyengine_uk/variables/contrib/policyengine/nhs_budget_change.py @@ -8,14 +8,10 @@ class nhs_budget_change(Variable): value_type = float def formula(household, period, parameters): - budget_increase = ( - parameters(period).gov.contrib.policyengine.budget.nhs * 1e9 - ) + budget_increase = parameters(period).gov.contrib.policyengine.budget.nhs * 1e9 if budget_increase == 0: return 0 - decile = household( - "pre_budget_change_ons_household_income_decile", period - ) + decile = household("pre_budget_change_ons_household_income_decile", period) weight = household("household_weight", period) DECILE_INCIDENCE = { 1: 0.095, @@ -36,9 +32,7 @@ def formula(household, period, parameters): i: budget_increase * DECILE_INCIDENCE[i] for i in range(1, 11) } if household.simulation.dataset is not None: - households_per_decile = ( - pd.Series(weight).groupby(decile).sum().to_dict() - ) + households_per_decile = pd.Series(weight).groupby(decile).sum().to_dict() else: households_per_decile = {i: 28e5 for i in range(1, 11)} diff --git a/policyengine_uk/variables/contrib/policyengine/other_public_spending_budget_change.py b/policyengine_uk/variables/contrib/policyengine/other_public_spending_budget_change.py index 20758220c..ad55ff492 100644 --- a/policyengine_uk/variables/contrib/policyengine/other_public_spending_budget_change.py +++ b/policyengine_uk/variables/contrib/policyengine/other_public_spending_budget_change.py @@ -9,16 +9,12 @@ class other_public_spending_budget_change(Variable): def formula(household, period, parameters): budget_increase = ( - parameters( - period - ).gov.contrib.policyengine.budget.other_public_spending + parameters(period).gov.contrib.policyengine.budget.other_public_spending * 1e9 ) if budget_increase == 0: return 0 - decile = household( - "pre_budget_change_ons_household_income_decile", period - ) + decile = household("pre_budget_change_ons_household_income_decile", period) weight = household("household_weight", period) DECILE_INCIDENCE = { 1: 0.114, @@ -38,9 +34,7 @@ def formula(household, period, parameters): i: budget_increase * DECILE_INCIDENCE[i] for i in range(1, 11) } if household.simulation.dataset is not None: - households_per_decile = ( - pd.Series(weight).groupby(decile).sum().to_dict() - ) + households_per_decile = pd.Series(weight).groupby(decile).sum().to_dict() else: households_per_decile = {i: 28e5 for i in range(1, 11)} diff --git a/policyengine_uk/variables/contrib/policyengine/pre_budget_change_household_benefits.py b/policyengine_uk/variables/contrib/policyengine/pre_budget_change_household_benefits.py index 56f03f58e..702015d95 100644 --- a/policyengine_uk/variables/contrib/policyengine/pre_budget_change_household_benefits.py +++ b/policyengine_uk/variables/contrib/policyengine/pre_budget_change_household_benefits.py @@ -46,18 +46,12 @@ def formula(household, period, parameters): benefits = pre_budget_change_household_benefits.adds if contrib.abolish_council_tax: benefits = [ - benefit - for benefit in benefits - if benefit != "council_tax_benefit" + benefit for benefit in benefits if benefit != "council_tax_benefit" ] general_benefits = add( household, period, - [ - benefit - for benefit in benefits - if benefit not in ["basic_income"] - ], + [benefit for benefit in benefits if benefit not in ["basic_income"]], ) non_sp_benefits = add( household, diff --git a/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_household_phaseout.py b/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_household_phaseout.py index b6df7e5ba..1edff6855 100644 --- a/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_household_phaseout.py +++ b/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_household_phaseout.py @@ -4,9 +4,7 @@ class bi_household_phaseout(Variable): label = "Basic income phase-out (household)" - documentation = ( - "Reduction in basic income from household-level phase-outs." - ) + documentation = "Reduction in basic income from household-level phase-outs." entity = Person definition_period = YEAR value_type = float @@ -26,14 +24,10 @@ def formula(person, period, parameters): household_income - bi.phase_out.household.threshold, 0, ) - uncapped_deduction = ( - bi.phase_out.household.rate * income_over_threshold - ) + uncapped_deduction = bi.phase_out.household.rate * income_over_threshold capped_deduction = min_(household_bi, uncapped_deduction) warnings.filterwarnings("ignore") - percent_reduction = where( - household_bi > 0, capped_deduction / household_bi, 0 - ) + percent_reduction = where(household_bi > 0, capped_deduction / household_bi, 0) return percent_reduction * remaining_bi diff --git a/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_individual_phaseout.py b/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_individual_phaseout.py index 2e974dbf5..41d287e60 100644 --- a/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_individual_phaseout.py +++ b/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_individual_phaseout.py @@ -4,9 +4,7 @@ class bi_individual_phaseout(Variable): label = "Basic income phase-out (individual)" - documentation = ( - "Reduction in basic income from individual-level phase-outs." - ) + documentation = "Reduction in basic income from individual-level phase-outs." entity = Person definition_period = YEAR value_type = float @@ -16,10 +14,6 @@ def formula(person, period, parameters): income = person("total_income", period) bi = parameters(period).gov.contrib.ubi_center.basic_income max_bi = person("bi_maximum", period) - income_over_threshold = max_( - income - bi.phase_out.individual.threshold, 0 - ) - uncapped_deduction = ( - bi.phase_out.individual.rate * income_over_threshold - ) + income_over_threshold = max_(income - bi.phase_out.individual.threshold, 0) + uncapped_deduction = bi.phase_out.individual.rate * income_over_threshold return min_(max_bi, uncapped_deduction) diff --git a/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_maximum.py b/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_maximum.py index 95e77f402..07ce39159 100644 --- a/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_maximum.py +++ b/policyengine_uk/variables/contrib/ubi_center/basic_income/bi_maximum.py @@ -13,9 +13,7 @@ def formula(person, period, parameters): weekly_flat_amount = bi.amount.flat is_senior_for_bi = person("is_SP_age", period) age = person("age", period) - is_child_for_bi = (age < bi.amount.adult_age) * ( - age >= bi.amount.child_min_age - ) + is_child_for_bi = (age < bi.amount.adult_age) * (age >= bi.amount.child_min_age) is_adult_for_bi = (age >= bi.amount.adult_age) * ~is_senior_for_bi weekly_amount_by_age = select( [is_child_for_bi, is_senior_for_bi, is_adult_for_bi], diff --git a/policyengine_uk/variables/contrib/ubi_center/carbon_tax.py b/policyengine_uk/variables/contrib/ubi_center/carbon_tax.py index 01cca8d19..5df088aec 100644 --- a/policyengine_uk/variables/contrib/ubi_center/carbon_tax.py +++ b/policyengine_uk/variables/contrib/ubi_center/carbon_tax.py @@ -14,14 +14,9 @@ def formula(household, period, parameters): emissions = household("carbon_consumption", period) # Household's share of total stocks and other corporate tax exposure. shareholding = household("shareholding", period) - total_emissions = ( - emissions * household("household_weight", period) - ).sum() + total_emissions = (emissions * household("household_weight", period)).sum() consumer_incidence = carbon_tax.consumer_incidence * rate * emissions corporate_incidence = ( - (1 - carbon_tax.consumer_incidence) - * rate - * total_emissions - * shareholding + (1 - carbon_tax.consumer_incidence) * rate * total_emissions * shareholding ) return consumer_incidence + corporate_incidence diff --git a/policyengine_uk/variables/contrib/ubi_center/land_value_tax.py b/policyengine_uk/variables/contrib/ubi_center/land_value_tax.py index c29bdb0d1..d0227fda8 100644 --- a/policyengine_uk/variables/contrib/ubi_center/land_value_tax.py +++ b/policyengine_uk/variables/contrib/ubi_center/land_value_tax.py @@ -11,10 +11,6 @@ class LVT(Variable): def formula(household, period, parameters): lvt = parameters(period).gov.contrib.ubi_center.land_value_tax full_lvt = lvt.rate * household("land_value", period) - household_lvt = lvt.household_rate * household( - "household_land_value", period - ) - corporate_lvt = lvt.corporate_rate * household( - "corporate_land_value", period - ) + household_lvt = lvt.household_rate * household("household_land_value", period) + corporate_lvt = lvt.corporate_rate * household("corporate_land_value", period) return full_lvt + household_lvt + corporate_lvt diff --git a/policyengine_uk/variables/gov/dcms/bbc/tv_licence/tv_licence_discount.py b/policyengine_uk/variables/gov/dcms/bbc/tv_licence/tv_licence_discount.py index b30f50a3d..ffc499db1 100644 --- a/policyengine_uk/variables/gov/dcms/bbc/tv_licence/tv_licence_discount.py +++ b/policyengine_uk/variables/gov/dcms/bbc/tv_licence/tv_licence_discount.py @@ -20,13 +20,9 @@ def formula(household, period, parameters): aged = person("age", period) >= tv_licence.discount.aged.min_age has_aged = household.any(aged) claims_pc = add(household, period, ["pension_credit"]) > 0 - meets_pc_requirement = ( - not_(tv_licence.discount.aged.must_claim_pc) | claims_pc - ) + meets_pc_requirement = not_(tv_licence.discount.aged.must_claim_pc) | claims_pc eligible_for_aged_discount = has_aged & meets_pc_requirement - aged_discount = ( - eligible_for_aged_discount * tv_licence.discount.aged.discount - ) + aged_discount = eligible_for_aged_discount * tv_licence.discount.aged.discount # Blind discount is_blind = person("is_blind", period) diff --git a/policyengine_uk/variables/gov/dfe/care_to_learn/would_claim_care_to_learn.py b/policyengine_uk/variables/gov/dfe/care_to_learn/would_claim_care_to_learn.py index b6a7fad53..66067c6f2 100644 --- a/policyengine_uk/variables/gov/dfe/care_to_learn/would_claim_care_to_learn.py +++ b/policyengine_uk/variables/gov/dfe/care_to_learn/would_claim_care_to_learn.py @@ -5,8 +5,6 @@ class would_claim_care_to_learn(Variable): value_type = bool entity = BenUnit label = "would claim Care to Learn" - documentation = ( - "Whether this BenUnit would claim Care to Learn if eligible" - ) + documentation = "Whether this BenUnit would claim Care to Learn if eligible" definition_period = YEAR default_value = True diff --git a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_meets_income_requirements.py b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_meets_income_requirements.py index 6130ba5a3..b20e41db8 100644 --- a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_meets_income_requirements.py +++ b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_meets_income_requirements.py @@ -15,9 +15,7 @@ def formula(person, period, parameters): p = parameters(period).gov.dfe.extended_childcare_entitlement # Calculate eligible income by summing countable sources - yearly_eligible_income = add( - person, period, p.income.countable_sources - ) + yearly_eligible_income = add(person, period, p.income.countable_sources) quarterly_income = yearly_eligible_income / 4 # Get minimum wage rate using existing variable diff --git a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_work_condition.py b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_work_condition.py index 9e8164809..b62b285bf 100644 --- a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_work_condition.py +++ b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/conditions/extended_childcare_entitlement_work_condition.py @@ -15,14 +15,11 @@ def formula(person, period, parameters): # Get disability status p = parameters(period).gov.dfe.extended_childcare_entitlement - eligible_based_on_disability = ( - add(person, period, p.disability_criteria) > 0 - ) + eligible_based_on_disability = add(person, period, p.disability_criteria) > 0 # Adjust eligibility based on the summed UC Carer Element: 11A(1)(c) - eligible_based_on_disability_or_carer = ( - eligible_based_on_disability - | (benunit("uc_carer_element", period) > 0) + eligible_based_on_disability_or_carer = eligible_based_on_disability | ( + benunit("uc_carer_element", period) > 0 ) # Count parents in benefit unit @@ -32,12 +29,8 @@ def formula(person, period, parameters): lone_parent_eligible = (parent_count == 1) & in_work # Break out the complex nested conditions for couples - all_parents_working = benunit.all( - in_work | ~person("is_parent", period) - ) - some_parents_working = benunit.any( - in_work & person("is_parent", period) - ) + all_parents_working = benunit.all(in_work | ~person("is_parent", period)) + some_parents_working = benunit.any(in_work & person("is_parent", period)) any_parent_disability_eligible = benunit.any( eligible_based_on_disability_or_carer & person("is_parent", period) ) diff --git a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement.py b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement.py index 818fc60a4..17aa6da3f 100644 --- a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement.py +++ b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement.py @@ -15,22 +15,16 @@ def formula(benunit, period, parameters): age = benunit.members("age", period) # Compute weekly hours directly inside this function - weekly_hours_per_child = p.extended_childcare_entitlement.hours.calc( - age - ) + weekly_hours_per_child = p.extended_childcare_entitlement.hours.calc(age) # Get max hours used per child - max_hours_used = benunit.members( - "max_free_entitlement_hours_used", period - ) + max_hours_used = benunit.members("max_free_entitlement_hours_used", period) # Use the appropriate hours based on the condition weekly_hours_to_use = min_(max_hours_used, weekly_hours_per_child) # Get the maximum hours usage for this benefit unit - maximum_hours_usage = benunit( - "maximum_extended_childcare_hours_usage", period - ) + maximum_hours_usage = benunit("maximum_extended_childcare_hours_usage", period) # Apply the maximum hours limit weekly_hours_to_use = min_( @@ -38,8 +32,8 @@ def formula(benunit, period, parameters): ) # Compute weekly subsidy per child - weekly_subsidy_per_child = ( - weekly_hours_to_use * p.childcare_funding_rate.calc(age) + weekly_subsidy_per_child = weekly_hours_to_use * p.childcare_funding_rate.calc( + age ) # Compute total annual expenses diff --git a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement_eligible.py b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement_eligible.py index c7bc26dce..dc2ffb606 100644 --- a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement_eligible.py +++ b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/extended_childcare_entitlement_eligible.py @@ -24,8 +24,7 @@ def formula(benunit, period, parameters): # Check work condition work_eligible = ( - benunit("extended_childcare_entitlement_work_condition", period) - > 0 + benunit("extended_childcare_entitlement_work_condition", period) > 0 ) return in_england & meets_income_condition & work_eligible diff --git a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/maximum_extended_childcare_hours_usage.py b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/maximum_extended_childcare_hours_usage.py index b41482ac1..c5b542d29 100644 --- a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/maximum_extended_childcare_hours_usage.py +++ b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/maximum_extended_childcare_hours_usage.py @@ -5,6 +5,8 @@ class maximum_extended_childcare_hours_usage(Variable): value_type = float entity = BenUnit label = "maximum extended childcare hours used" - documentation = "The maximum number of weekly extended childcare hours that this family uses" + documentation = ( + "The maximum number of weekly extended childcare hours that this family uses" + ) definition_period = YEAR default_value = 30 # By default, uses up to 30 hours per week diff --git a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/would_claim_extended_childcare.py b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/would_claim_extended_childcare.py index 070c50542..9c9e89034 100644 --- a/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/would_claim_extended_childcare.py +++ b/policyengine_uk/variables/gov/dfe/extended_childcare_entitlement/would_claim_extended_childcare.py @@ -5,6 +5,8 @@ class would_claim_extended_childcare(Variable): value_type = bool entity = BenUnit label = "would claim extended childcare entitlement" - documentation = "Whether this family would claim extended childcare entitlement if eligible" + documentation = ( + "Whether this family would claim extended childcare entitlement if eligible" + ) definition_period = YEAR default_value = True diff --git a/policyengine_uk/variables/gov/dfe/max_free_entitlement_hours_used.py b/policyengine_uk/variables/gov/dfe/max_free_entitlement_hours_used.py index 3dc51f346..75bd107d8 100644 --- a/policyengine_uk/variables/gov/dfe/max_free_entitlement_hours_used.py +++ b/policyengine_uk/variables/gov/dfe/max_free_entitlement_hours_used.py @@ -5,6 +5,8 @@ class max_free_entitlement_hours_used(Variable): value_type = float entity = Person label = "maximum hours of free childcare entitlement used" - documentation = "The maximum weekly hours of free childcare entitlement used by the person" + documentation = ( + "The maximum weekly hours of free childcare entitlement used by the person" + ) definition_period = YEAR default_value = 30 diff --git a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_tax_credit_criteria_for_targeted_childcare_entitlement.py b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_tax_credit_criteria_for_targeted_childcare_entitlement.py index 4a557c189..94b629adf 100644 --- a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_tax_credit_criteria_for_targeted_childcare_entitlement.py +++ b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_tax_credit_criteria_for_targeted_childcare_entitlement.py @@ -10,13 +10,9 @@ class meets_tax_credit_criteria_for_targeted_childcare_entitlement(Variable): def formula(benunit, period, parameters): p = parameters(period).gov.dfe.targeted_childcare_entitlement - tax_credits = add( - benunit, period, ["child_tax_credit", "working_tax_credit"] - ) + tax_credits = add(benunit, period, ["child_tax_credit", "working_tax_credit"]) - tax_credits_applicable_income = benunit( - "tax_credits_applicable_income", period - ) + tax_credits_applicable_income = benunit("tax_credits_applicable_income", period) # Check Tax Credits eligibility # Legislation source for total (applicable) income limit:The Local Authority Regulations 2014, part 1.2.b diff --git a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_universal_credit_criteria_for_targeted_childcare_entitlement.py b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_universal_credit_criteria_for_targeted_childcare_entitlement.py index 42fa2d5c2..52a75c07b 100644 --- a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_universal_credit_criteria_for_targeted_childcare_entitlement.py +++ b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/meets_universal_credit_criteria_for_targeted_childcare_entitlement.py @@ -1,14 +1,10 @@ from policyengine_uk.model_api import * -class meets_universal_credit_criteria_for_targeted_childcare_entitlement( - Variable -): +class meets_universal_credit_criteria_for_targeted_childcare_entitlement(Variable): value_type = bool entity = BenUnit - label = ( - "meets Universal Credit criteria for targeted childcare entitlement" - ) + label = "meets Universal Credit criteria for targeted childcare entitlement" definition_period = YEAR def formula(benunit, period, parameters): diff --git a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement.py b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement.py index c5e3e7ef4..a411df360 100644 --- a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement.py +++ b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement.py @@ -12,13 +12,8 @@ class targeted_childcare_entitlement(Variable): def formula(person, period, parameters): p = parameters(period).gov.dfe age = person("age", period) - eligible_by_age = ( - p.targeted_childcare_entitlement.age_eligibility.calc(age) - ) - hours = ( - p.targeted_childcare_entitlement.hours_entitlement - * eligible_by_age - ) + eligible_by_age = p.targeted_childcare_entitlement.age_eligibility.calc(age) + hours = p.targeted_childcare_entitlement.hours_entitlement * eligible_by_age max_hours_used = person("max_free_entitlement_hours_used", period) weeks = p.weeks_per_year total_hours_used = max_hours_used * weeks diff --git a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement_eligible.py b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement_eligible.py index 6e7fed0fe..5439f61f4 100644 --- a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement_eligible.py +++ b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/targeted_childcare_entitlement_eligible.py @@ -23,9 +23,7 @@ def formula(benunit, period, parameters): ) # Check if household receives any qualifying benefits - has_qualifying_benefits = ( - add(benunit, period, p.qualifying_benefits) > 0 - ) + has_qualifying_benefits = add(benunit, period, p.qualifying_benefits) > 0 # Check if household meets any additional qualifying criteria # from qualifying_criteria.yaml (UC/TC specific criteria) diff --git a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/would_claim_targeted_childcare.py b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/would_claim_targeted_childcare.py index bb755228f..5030a1a39 100644 --- a/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/would_claim_targeted_childcare.py +++ b/policyengine_uk/variables/gov/dfe/targeted_childcare_entitlement/would_claim_targeted_childcare.py @@ -5,6 +5,8 @@ class would_claim_targeted_childcare(Variable): value_type = bool entity = BenUnit label = "would claim targeted childcare entitlement" - documentation = "Whether this family would claim targeted childcare entitlement if eligible" + documentation = ( + "Whether this family would claim targeted childcare entitlement if eligible" + ) definition_period = YEAR default_value = True diff --git a/policyengine_uk/variables/gov/dfe/universal_childcare_entitlement/would_claim_universal_childcare.py b/policyengine_uk/variables/gov/dfe/universal_childcare_entitlement/would_claim_universal_childcare.py index b6066b4bc..e5342278a 100644 --- a/policyengine_uk/variables/gov/dfe/universal_childcare_entitlement/would_claim_universal_childcare.py +++ b/policyengine_uk/variables/gov/dfe/universal_childcare_entitlement/would_claim_universal_childcare.py @@ -5,6 +5,8 @@ class would_claim_universal_childcare(Variable): value_type = bool entity = BenUnit label = "would claim universal childcare entitlement" - documentation = "Whether this BenUnit would claim universal childcare entitlement if eligible" + documentation = ( + "Whether this BenUnit would claim universal childcare entitlement if eligible" + ) definition_period = YEAR default_value = True diff --git a/policyengine_uk/variables/gov/dhsc/outpatient/nhs_outpatient_spending.py b/policyengine_uk/variables/gov/dhsc/outpatient/nhs_outpatient_spending.py index 91a716486..4f75f6659 100644 --- a/policyengine_uk/variables/gov/dhsc/outpatient/nhs_outpatient_spending.py +++ b/policyengine_uk/variables/gov/dhsc/outpatient/nhs_outpatient_spending.py @@ -3,9 +3,7 @@ class nhs_outpatient_spending(Variable): label = "NHS spending on outpatient visits" - documentation = ( - "Total spending by the NHS on outpatient visits for this person." - ) + documentation = "Total spending by the NHS on outpatient visits for this person." entity = Person definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/dwp/CTC_severely_disabled_child_element.py b/policyengine_uk/variables/gov/dwp/CTC_severely_disabled_child_element.py index 865b9779e..5ab51461c 100644 --- a/policyengine_uk/variables/gov/dwp/CTC_severely_disabled_child_element.py +++ b/policyengine_uk/variables/gov/dwp/CTC_severely_disabled_child_element.py @@ -21,6 +21,4 @@ def formula(benunit, period, parameters): ) severely_disabled_children = benunit.sum(is_severely_disabled_child) CTC = parameters(period).gov.dwp.tax_credits.child_tax_credit - return ( - CTC.elements.severe_dis_child_element * severely_disabled_children - ) + return CTC.elements.severe_dis_child_element * severely_disabled_children diff --git a/policyengine_uk/variables/gov/dwp/LHA_allowed_bedrooms.py b/policyengine_uk/variables/gov/dwp/LHA_allowed_bedrooms.py index 85ccc664d..9dff0c03c 100644 --- a/policyengine_uk/variables/gov/dwp/LHA_allowed_bedrooms.py +++ b/policyengine_uk/variables/gov/dwp/LHA_allowed_bedrooms.py @@ -31,9 +31,9 @@ def formula(benunit, period, parameters): under_10 = age < 10 child_over_10 = ~under_10 & under_16 # One room each for over-16s outside the benefit unit - non_dependants = benunit.max( - person.household.sum(~under_16) - ) - benunit.sum(~under_16) + non_dependants = benunit.max(person.household.sum(~under_16)) - benunit.sum( + ~under_16 + ) boys_under_10 = benunit.sum(under_10 & male) boys_over_10 = benunit.sum(child_over_10 & male) girls_under_10 = benunit.sum(under_10 & ~male) @@ -44,14 +44,8 @@ def formula(benunit, period, parameters): space_for_boy_under_10 = boys_over_10 % 2 space_for_girl_under_10 = girls_over_10 % 2 # Have those spaces filled where possible by children under 10 - left_over_boys_under_10 = max_( - boys_under_10 - space_for_boy_under_10, 0 - ) - left_over_girls_under_10 = max_( - girls_under_10 - space_for_girl_under_10, 0 - ) + left_over_boys_under_10 = max_(boys_under_10 - space_for_boy_under_10, 0) + left_over_girls_under_10 = max_(girls_under_10 - space_for_girl_under_10, 0) # The remaining children must share in pairs - under_10_rooms = ( - left_over_boys_under_10 + left_over_girls_under_10 + 1 - ) // 2 + under_10_rooms = (left_over_boys_under_10 + left_over_girls_under_10 + 1) // 2 return 1 + non_dependants + over_10_rooms + under_10_rooms diff --git a/policyengine_uk/variables/gov/dwp/LHA_category.py b/policyengine_uk/variables/gov/dwp/LHA_category.py index 6e84d5132..093112d4b 100644 --- a/policyengine_uk/variables/gov/dwp/LHA_category.py +++ b/policyengine_uk/variables/gov/dwp/LHA_category.py @@ -26,15 +26,9 @@ def formula(benunit, period, parameters): num_rooms = benunit("LHA_allowed_bedrooms", period.this_year) person = benunit.members household = person.household - is_shared = benunit.any( - household("is_shared_accommodation", period.this_year) - ) - num_adults_in_hh = benunit.max( - household.sum(person("is_adult", period)) - ) - eldest_adult_age_in_hh = benunit.max( - household.max(person("age", period)) - ) + is_shared = benunit.any(household("is_shared_accommodation", period.this_year)) + num_adults_in_hh = benunit.max(household.sum(person("is_adult", period))) + eldest_adult_age_in_hh = benunit.max(household.max(person("age", period))) has_children = benunit.any(person("is_child", period)) # Households with only one adult, if under age threshold, can only # claim shared if without children: diff --git a/policyengine_uk/variables/gov/dwp/LHA_eligible.py b/policyengine_uk/variables/gov/dwp/LHA_eligible.py index 2a7d31bdb..008e3f822 100644 --- a/policyengine_uk/variables/gov/dwp/LHA_eligible.py +++ b/policyengine_uk/variables/gov/dwp/LHA_eligible.py @@ -10,9 +10,7 @@ class LHA_eligible(Variable): value_type = bool entity = BenUnit label = "Eligibility for Local Housing Allowance" - documentation = ( - "Whether benefit unit is eligible for Local Housing Allowance" - ) + documentation = "Whether benefit unit is eligible for Local Housing Allowance" definition_period = YEAR def formula(benunit, period, parameters): diff --git a/policyengine_uk/variables/gov/dwp/WTC_basic_element.py b/policyengine_uk/variables/gov/dwp/WTC_basic_element.py index 6d914b550..237bc2178 100644 --- a/policyengine_uk/variables/gov/dwp/WTC_basic_element.py +++ b/policyengine_uk/variables/gov/dwp/WTC_basic_element.py @@ -11,6 +11,4 @@ class WTC_basic_element(Variable): defined_for = "is_WTC_eligible" def formula(benunit, period, parameters): - return parameters( - period - ).gov.dwp.tax_credits.working_tax_credit.elements.basic + return parameters(period).gov.dwp.tax_credits.working_tax_credit.elements.basic diff --git a/policyengine_uk/variables/gov/dwp/WTC_disabled_element.py b/policyengine_uk/variables/gov/dwp/WTC_disabled_element.py index 48ff30c18..9bbaf94f7 100644 --- a/policyengine_uk/variables/gov/dwp/WTC_disabled_element.py +++ b/policyengine_uk/variables/gov/dwp/WTC_disabled_element.py @@ -13,9 +13,7 @@ class WTC_disabled_element(Variable): def formula(benunit, period, parameters): WTC = parameters(period).gov.dwp.tax_credits.working_tax_credit person = benunit.members - person_meets_hours = ( - person("weekly_hours", period) >= WTC.min_hours.lower - ) + person_meets_hours = person("weekly_hours", period) >= WTC.min_hours.lower person_qualifies = ( person_meets_hours & person("is_disabled_for_benefits", period) diff --git a/policyengine_uk/variables/gov/dwp/basic_state_pension.py b/policyengine_uk/variables/gov/dwp/basic_state_pension.py index 60ce503f9..14e145824 100644 --- a/policyengine_uk/variables/gov/dwp/basic_state_pension.py +++ b/policyengine_uk/variables/gov/dwp/basic_state_pension.py @@ -37,9 +37,7 @@ def formula(person, period, parameters): # Apply triple lock uprating only when using dataset # (i.e., when data year differs from simulation period) if has_dataset: - triple_lock = ( - parameters.gov.economic_assumptions.indices.triple_lock - ) + triple_lock = parameters.gov.economic_assumptions.indices.triple_lock uprating = triple_lock(period) / triple_lock(data_year) else: uprating = 1 diff --git a/policyengine_uk/variables/gov/dwp/benefit_cap_reduction.py b/policyengine_uk/variables/gov/dwp/benefit_cap_reduction.py index da64022ac..bb0fddc2a 100644 --- a/policyengine_uk/variables/gov/dwp/benefit_cap_reduction.py +++ b/policyengine_uk/variables/gov/dwp/benefit_cap_reduction.py @@ -23,7 +23,6 @@ def formula(benunit, period, parameters): "sda", ] return max_( - add(benunit, period, CAPPED_BENEFITS) - - benunit("benefit_cap", period), + add(benunit, period, CAPPED_BENEFITS) - benunit("benefit_cap", period), 0, ) diff --git a/policyengine_uk/variables/gov/dwp/child_tax_credit_pre_minimum.py b/policyengine_uk/variables/gov/dwp/child_tax_credit_pre_minimum.py index c85a8f9e7..b3df8b4f2 100644 --- a/policyengine_uk/variables/gov/dwp/child_tax_credit_pre_minimum.py +++ b/policyengine_uk/variables/gov/dwp/child_tax_credit_pre_minimum.py @@ -5,9 +5,7 @@ class child_tax_credit_pre_minimum(Variable): value_type = float entity = BenUnit label = "Child Tax Credit pre-minimum" - documentation = ( - "Child Tax Credit amount before the minimum tax credit is applied" - ) + documentation = "Child Tax Credit amount before the minimum tax credit is applied" defined_for = "would_claim_CTC" definition_period = YEAR unit = GBP diff --git a/policyengine_uk/variables/gov/dwp/ctc_child_limit_affected.py b/policyengine_uk/variables/gov/dwp/ctc_child_limit_affected.py index 4c1ff5961..56f725b20 100644 --- a/policyengine_uk/variables/gov/dwp/ctc_child_limit_affected.py +++ b/policyengine_uk/variables/gov/dwp/ctc_child_limit_affected.py @@ -20,6 +20,5 @@ def formula(benunit, period, parameters): spaces_left, benunit.sum(is_child_for_CTC) - exempt_children ) return ( - exempt_children + non_exempt_children - < benunit.sum(is_child_for_CTC) + exempt_children + non_exempt_children < benunit.sum(is_child_for_CTC) ) & (benunit("child_tax_credit", period) > 0) diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income.py b/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income.py index fad9620ff..4e188b556 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income.py @@ -43,17 +43,13 @@ def formula(benunit, period, parameters): # Basic income is already in personal benefits, deduct if needed increased_income -= add(benunit, period, ["basic_income"]) # Reduce increased income by pension contributions and tax - pension_contributions = ( - add(benunit, period, ["pension_contributions"]) * 0.5 - ) + pension_contributions = add(benunit, period, ["pension_contributions"]) * 0.5 TAX_COMPONENTS = ["income_tax", "national_insurance"] tax = add(benunit, period, TAX_COMPONENTS) increased_income_reduced_by_tax_and_pensions = ( increased_income - tax - pension_contributions ) - disregard = benunit( - "housing_benefit_applicable_income_disregard", period - ) + disregard = benunit("housing_benefit_applicable_income_disregard", period) childcare_element = benunit( "housing_benefit_applicable_income_childcare_element", period ) diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income_disregard.py b/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income_disregard.py index 62972c050..1722ced06 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income_disregard.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/applicable_income/housing_benefit_applicable_income_disregard.py @@ -10,9 +10,7 @@ class housing_benefit_applicable_income_disregard(Variable): def formula(benunit, period, parameters): WTC = parameters(period).gov.dwp.tax_credits.working_tax_credit - p = parameters( - period - ).gov.dwp.housing_benefit.means_test.income_disregard + p = parameters(period).gov.dwp.housing_benefit.means_test.income_disregard hours = add(benunit, period, ["weekly_hours"]) # Calculate single, couple, lone parent, and worker disregards. single = benunit("is_single_person", period) @@ -21,9 +19,7 @@ def formula(benunit, period, parameters): couple_disregard = couple * p.couple lone_parent = benunit("is_lone_parent", period) lone_parent_disregard = lone_parent * p.lone_parent - hour_requirement = where( - lone_parent, WTC.min_hours.lower, p.worker_hours - ) + hour_requirement = where(lone_parent, WTC.min_hours.lower, p.worker_hours) worker = hours > hour_requirement worker_disregard = worker * p.worker weekly_disregard = ( diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/entitlement/housing_benefit_entitlement.py b/policyengine_uk/variables/gov/dwp/housing_benefit/entitlement/housing_benefit_entitlement.py index f61a736ca..f44c35d13 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/entitlement/housing_benefit_entitlement.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/entitlement/housing_benefit_entitlement.py @@ -10,9 +10,7 @@ class housing_benefit_entitlement(Variable): def formula(benunit, period, parameters): rent = benunit("benunit_rent", period) - applicable_amount = benunit( - "housing_benefit_applicable_amount", period - ) + applicable_amount = benunit("housing_benefit_applicable_amount", period) income = benunit("housing_benefit_applicable_income", period) withdrawal_rate = parameters( period @@ -22,6 +20,4 @@ def formula(benunit, period, parameters): capped_final_amount = min_(final_amount, benunit("LHA_cap", period)) lha_eligible = benunit("LHA_eligible", period.this_year) amount = where(lha_eligible, capped_final_amount, final_amount) - return max_( - 0, amount - benunit("housing_benefit_non_dep_deductions", period) - ) + return max_(0, amount - benunit("housing_benefit_non_dep_deductions", period)) diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit.py b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit.py index 39287a261..2b02130f7 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit.py @@ -10,8 +10,6 @@ class housing_benefit(Variable): defined_for = "would_claim_housing_benefit" def formula(benunit, period, parameters): - housing_benefit_entitlement = benunit( - "housing_benefit_pre_benefit_cap", period - ) + housing_benefit_entitlement = benunit("housing_benefit_pre_benefit_cap", period) benefit_cap_reduction = benunit("benefit_cap_reduction", period) return max_(0, housing_benefit_entitlement - benefit_cap_reduction) diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_eligible.py b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_eligible.py index f1b67e33f..2d152c028 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_eligible.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_eligible.py @@ -9,9 +9,7 @@ class housing_benefit_eligible(Variable): def formula(benunit, period, parameters): social = benunit.any(benunit.members("in_social_housing", period)) - already_claiming = ( - add(benunit, period, ["housing_benefit_reported"]) > 0 - ) + already_claiming = add(benunit, period, ["housing_benefit_reported"]) > 0 claiming_uc = benunit("would_claim_uc", period) lha_eligible = benunit("LHA_eligible", period) return already_claiming & (social | lha_eligible) & ~claiming_uc diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/would_claim_housing_benefit.py b/policyengine_uk/variables/gov/dwp/housing_benefit/would_claim_housing_benefit.py index 5136267b7..6c9df4b9b 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/would_claim_housing_benefit.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/would_claim_housing_benefit.py @@ -5,14 +5,10 @@ class would_claim_housing_benefit(Variable): value_type = bool entity = BenUnit label = "Would claim the Housing Benefit" - documentation = ( - "Whether this family would claim Housing Benefit if eligible" - ) + documentation = "Whether this family would claim Housing Benefit if eligible" definition_period = YEAR def formula(benunit, period, parameters): - claims_all_entitled_benefits = benunit( - "claims_all_entitled_benefits", period - ) + claims_all_entitled_benefits = benunit("claims_all_entitled_benefits", period) reported_hb = add(benunit, period, ["housing_benefit_reported"]) > 0 return claims_all_entitled_benefits | reported_hb diff --git a/policyengine_uk/variables/gov/dwp/income_support_applicable_income.py b/policyengine_uk/variables/gov/dwp/income_support_applicable_income.py index a3652c601..9469c8144 100644 --- a/policyengine_uk/variables/gov/dwp/income_support_applicable_income.py +++ b/policyengine_uk/variables/gov/dwp/income_support_applicable_income.py @@ -39,9 +39,7 @@ def formula(benunit, period, parameters): benunit("is_couple", period) * mt.income_disregard_couple ) lone_parent = family_type == families.LONE_PARENT - income_disregard_lone_parent = ( - lone_parent * mt.income_disregard_lone_parent - ) + income_disregard_lone_parent = lone_parent * mt.income_disregard_lone_parent income_disregard = ( income_disregard_single + income_disregard_couple diff --git a/policyengine_uk/variables/gov/dwp/income_support_eligible.py b/policyengine_uk/variables/gov/dwp/income_support_eligible.py index 53fa76932..a32167cca 100644 --- a/policyengine_uk/variables/gov/dwp/income_support_eligible.py +++ b/policyengine_uk/variables/gov/dwp/income_support_eligible.py @@ -14,9 +14,7 @@ def formula(benunit, period, parameters): has_carers = add(benunit, period, ["is_carer_for_benefits"]) > 0 none_SP_age = ~benunit.any(benunit.members("is_SP_age", period)) has_esa_income = benunit("esa_income", period) > 0 - already_claiming = ( - add(benunit, period, ["income_support_reported"]) > 0 - ) + already_claiming = add(benunit, period, ["income_support_reported"]) > 0 return ( (has_carers | lone_parent_with_young_child) & none_SP_age diff --git a/policyengine_uk/variables/gov/dwp/is_CTC_child_limit_exempt.py b/policyengine_uk/variables/gov/dwp/is_CTC_child_limit_exempt.py index d6b9e3dc8..9db8d7937 100644 --- a/policyengine_uk/variables/gov/dwp/is_CTC_child_limit_exempt.py +++ b/policyengine_uk/variables/gov/dwp/is_CTC_child_limit_exempt.py @@ -17,13 +17,13 @@ def formula(person, period, parameters): born_before_limit = person("birth_year", period) < limit_year # Reform proposal - age_exemption = parameters.gov.contrib.two_child_limit.age_exemption.child_tax_credit( - period + age_exemption = ( + parameters.gov.contrib.two_child_limit.age_exemption.child_tax_credit( + period + ) ) if age_exemption > 0: - is_exempt = person.benunit.any( - person("age", period) < age_exemption - ) + is_exempt = person.benunit.any(person("age", period) < age_exemption) return born_before_limit | is_exempt return born_before_limit diff --git a/policyengine_uk/variables/gov/dwp/is_CTC_eligible.py b/policyengine_uk/variables/gov/dwp/is_CTC_eligible.py index 3b6cafeb6..53a9b0a08 100644 --- a/policyengine_uk/variables/gov/dwp/is_CTC_eligible.py +++ b/policyengine_uk/variables/gov/dwp/is_CTC_eligible.py @@ -9,10 +9,9 @@ class is_CTC_eligible(Variable): reference = "Tax Credits Act 2002 s. 8" def formula(benunit, period, parameters): - already_claiming = ( - add(benunit, period, ["child_tax_credit_reported"]) > 0 - ) & (~add(benunit, period, ["would_claim_uc"]) > 0) + already_claiming = (add(benunit, period, ["child_tax_credit_reported"]) > 0) & ( + ~add(benunit, period, ["would_claim_uc"]) > 0 + ) return ( - benunit.any(benunit.members("is_child_for_CTC", period)) - & already_claiming + benunit.any(benunit.members("is_child_for_CTC", period)) & already_claiming ) diff --git a/policyengine_uk/variables/gov/dwp/is_WTC_eligible.py b/policyengine_uk/variables/gov/dwp/is_WTC_eligible.py index 6ab0ed507..9573cc48c 100644 --- a/policyengine_uk/variables/gov/dwp/is_WTC_eligible.py +++ b/policyengine_uk/variables/gov/dwp/is_WTC_eligible.py @@ -29,15 +29,11 @@ def formula(benunit, period, parameters): higher_req = eldest_25_plus & youngest_under_60 # Calculate eligibility for each WTC group. meets_lower = total_hours >= WTC.min_hours.lower - meets_medium_total_hours = ( - total_hours >= WTC.min_hours.couple_with_children - ) + meets_medium_total_hours = total_hours >= WTC.min_hours.couple_with_children meets_medium_person_hours = max_person_hours >= WTC.min_hours.lower meets_medium = meets_medium_total_hours & meets_medium_person_hours meets_higher = total_hours >= WTC.min_hours.default - already_claiming = ( - add(benunit, period, ["working_tax_credit_reported"]) > 0 - ) + already_claiming = add(benunit, period, ["working_tax_credit_reported"]) > 0 return ( (lower_req & meets_lower) | (medium_req & meets_medium) diff --git a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt.py b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt.py index aca1668f3..563b34085 100644 --- a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt.py +++ b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt.py @@ -4,16 +4,12 @@ class is_benefit_cap_exempt(Variable): value_type = bool entity = BenUnit - label = ( - "Whether exempt from the benefits cap because of health or disability" - ) + label = "Whether exempt from the benefits cap because of health or disability" definition_period = YEAR reference = "https://www.gov.uk/benefit-cap/when-youre-not-affected" def formula(benunit, period, parameters): - exempt_health = benunit( - "is_benefit_cap_exempt_health_disability", period - ) + exempt_health = benunit("is_benefit_cap_exempt_health_disability", period) exempt_other = benunit("is_benefit_cap_exempt_other", period) exempt_earnings = benunit("is_benefit_cap_exempt_earnings", period) return exempt_health | exempt_earnings | exempt_other diff --git a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_earnings.py b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_earnings.py index 9b67e54d6..c27e13c39 100644 --- a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_earnings.py +++ b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_earnings.py @@ -16,9 +16,7 @@ def formula(benunit, period, parameters): # UC-specific exemptions # Limited capability for work and work-related activity - has_lcwra = benunit.any( - person("uc_limited_capability_for_WRA", period) - ) + has_lcwra = benunit.any(person("uc_limited_capability_for_WRA", period)) # Carer element in UC indicates caring for someone with disability gets_uc_carer_element = benunit("uc_carer_element", period) > 0 @@ -50,12 +48,8 @@ def formula(benunit, period, parameters): "working_tax_credit", # If getting WTC, likely working enough ] - qualifying_personal_benefits = add( - benunit, period, QUAL_PERSONAL_BENEFITS - ) - qualifying_benunit_benefits = add( - benunit, period, QUAL_BENUNIT_BENEFITS - ) + qualifying_personal_benefits = add(benunit, period, QUAL_PERSONAL_BENEFITS) + qualifying_benunit_benefits = add(benunit, period, QUAL_BENUNIT_BENEFITS) # Check for Armed Forces Compensation Scheme payments afcs = benunit("afcs", period) > 0 diff --git a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_health_disability.py b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_health_disability.py index e9b45275f..d92ea14a2 100644 --- a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_health_disability.py +++ b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_health_disability.py @@ -4,9 +4,7 @@ class is_benefit_cap_exempt_health_disability(Variable): value_type = bool entity = BenUnit - label = ( - "Whether exempt from the benefits cap because of health or disability" - ) + label = "Whether exempt from the benefits cap because of health or disability" definition_period = YEAR reference = "https://www.gov.uk/benefit-cap/when-youre-not-affected" @@ -18,9 +16,7 @@ def formula(benunit, period, parameters): # UC-specific exemptions # Limited capability for work and work-related activity - has_lcwra = benunit.any( - person("uc_limited_capability_for_WRA", period) - ) + has_lcwra = benunit.any(person("uc_limited_capability_for_WRA", period)) # Carer element in UC indicates caring for someone with disability gets_uc_carer_element = benunit("uc_carer_element", period) > 0 @@ -52,12 +48,8 @@ def formula(benunit, period, parameters): "working_tax_credit", # If getting WTC, likely working enough ] - qualifying_personal_benefits = add( - benunit, period, QUAL_PERSONAL_BENEFITS - ) - qualifying_benunit_benefits = add( - benunit, period, QUAL_BENUNIT_BENEFITS - ) + qualifying_personal_benefits = add(benunit, period, QUAL_PERSONAL_BENEFITS) + qualifying_benunit_benefits = add(benunit, period, QUAL_BENUNIT_BENEFITS) # Check for Armed Forces Compensation Scheme payments afcs = benunit("afcs", period) > 0 diff --git a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_other.py b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_other.py index 2f485d5b1..0fb154750 100644 --- a/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_other.py +++ b/policyengine_uk/variables/gov/dwp/is_benefit_cap_exempt_other.py @@ -16,9 +16,7 @@ def formula(benunit, period, parameters): # UC-specific exemptions # Limited capability for work and work-related activity - has_lcwra = benunit.any( - person("uc_limited_capability_for_WRA", period) - ) + has_lcwra = benunit.any(person("uc_limited_capability_for_WRA", period)) # Carer element in UC indicates caring for someone with disability gets_uc_carer_element = benunit("uc_carer_element", period) > 0 @@ -50,12 +48,8 @@ def formula(benunit, period, parameters): "working_tax_credit", # If getting WTC, likely working enough ] - qualifying_personal_benefits = add( - benunit, period, QUAL_PERSONAL_BENEFITS - ) - qualifying_benunit_benefits = add( - benunit, period, QUAL_BENUNIT_BENEFITS - ) + qualifying_personal_benefits = add(benunit, period, QUAL_PERSONAL_BENEFITS) + qualifying_benunit_benefits = add(benunit, period, QUAL_BENUNIT_BENEFITS) # Check for Armed Forces Compensation Scheme payments afcs = benunit("afcs", period) > 0 diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/carer_minimum_guarantee_addition.py b/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/carer_minimum_guarantee_addition.py index 0938e3676..01580baf1 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/carer_minimum_guarantee_addition.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/carer_minimum_guarantee_addition.py @@ -7,14 +7,10 @@ class carer_minimum_guarantee_addition(Variable): definition_period = YEAR value_type = float unit = GBP - reference = ( - "https://www.legislation.gov.uk/uksi/2002/1792/schedule/I/paragraph/4" - ) + reference = "https://www.legislation.gov.uk/uksi/2002/1792/schedule/I/paragraph/4" def formula(benunit, period, parameters): carers_allowance = benunit.members("carers_allowance", period) num_receiving_carers_allowance = benunit.sum(carers_allowance > 0) gc = parameters(period).gov.dwp.pension_credit.guarantee_credit - return ( - num_receiving_carers_allowance * gc.carer.addition * WEEKS_IN_YEAR - ) + return num_receiving_carers_allowance * gc.carer.addition * WEEKS_IN_YEAR diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/child_minimum_guarantee_addition.py b/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/child_minimum_guarantee_addition.py index 4add530a6..4b41a707d 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/child_minimum_guarantee_addition.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/child_minimum_guarantee_addition.py @@ -16,9 +16,7 @@ def formula(benunit, period, parameters): standard_disability_benefits = gc.child.disability.eligibility severe_disability_benefits = gc.child.disability.severe.eligibility is_disabled = add(person, period, standard_disability_benefits) > 0 - is_severely_disabled = ( - add(person, period, severe_disability_benefits) > 0 - ) + is_severely_disabled = add(person, period, severe_disability_benefits) > 0 is_standard_disabled = is_disabled & ~is_severely_disabled is_not_disabled = ~is_disabled per_child_amount = ( diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/severe_disability_minimum_guarantee_addition.py b/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/severe_disability_minimum_guarantee_addition.py index 9593aecf8..3c9ad944e 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/severe_disability_minimum_guarantee_addition.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/guarantee_credit/minimum_guarantee/additional/severe_disability_minimum_guarantee_addition.py @@ -7,9 +7,7 @@ class severe_disability_minimum_guarantee_addition(Variable): definition_period = YEAR value_type = float unit = GBP - reference = ( - "https://www.legislation.gov.uk/uksi/2002/1792/schedule/I/paragraph/1" - ) + reference = "https://www.legislation.gov.uk/uksi/2002/1792/schedule/I/paragraph/1" def formula(benunit, period, parameters): # 1. At least one adult receives a qualifying benefit @@ -20,9 +18,7 @@ def formula(benunit, period, parameters): ).gov.dwp.pension_credit.guarantee_credit.severe_disability relevant_benefits = severe_disability.relevant_benefits person = benunit.members - person_receives_qualifying_benefits = ( - add(person, period, relevant_benefits) > 0 - ) + person_receives_qualifying_benefits = add(person, period, relevant_benefits) > 0 is_adult = person("is_adult", period) count_eligible_adults = benunit.sum( is_adult & person_receives_qualifying_benefits @@ -30,9 +26,7 @@ def formula(benunit, period, parameters): any_children_without_benefits = ( benunit.sum(~is_adult & ~person_receives_qualifying_benefits) > 0 ) - carers_allowance_received = ( - add(benunit, period, ["carers_allowance"]) > 0 - ) + carers_allowance_received = add(benunit, period, ["carers_allowance"]) > 0 eligible = ~any_children_without_benefits & ~carers_allowance_received return ( eligible diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit.py b/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit.py index ed6f120ee..ab0687b35 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit.py @@ -17,9 +17,7 @@ def formula(benunit, period, parameters): minimum_guarantee = benunit("minimum_guarantee", period) income_over_threshold = max_(income - threshold, 0) income_over_mg = max_(income - minimum_guarantee, 0) - maximum_savings_credit = sc.rate.phase_in * ( - minimum_guarantee - threshold - ) + maximum_savings_credit = sc.rate.phase_in * (minimum_guarantee - threshold) phased_in_sc = min_( maximum_savings_credit, sc.rate.phase_in * income_over_threshold ) diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit_income.py b/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit_income.py index fe3e40e4f..f62e21e74 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit_income.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/savings_credit/savings_credit_income.py @@ -13,7 +13,5 @@ class savings_credit_income(Variable): def formula(benunit, period, parameters): guarantee_credit_income = benunit("pension_credit_income", period) pc = parameters(period).gov.dwp.pension_credit - excluded_income = add( - benunit, period, pc.savings_credit.excluded_income - ) + excluded_income = add(benunit, period, pc.savings_credit.excluded_income) return max_(0, guarantee_credit_income - excluded_income) diff --git a/policyengine_uk/variables/gov/dwp/tax_credits_applicable_income.py b/policyengine_uk/variables/gov/dwp/tax_credits_applicable_income.py index 50b88a619..d2d67ed01 100644 --- a/policyengine_uk/variables/gov/dwp/tax_credits_applicable_income.py +++ b/policyengine_uk/variables/gov/dwp/tax_credits_applicable_income.py @@ -7,7 +7,9 @@ class tax_credits_applicable_income(Variable): label = "Applicable income for Tax Credits" definition_period = YEAR unit = GBP - reference = "The Tax Credits (Definition and Calculation of Income) Regulations 2002 s. 3" + reference = ( + "The Tax Credits (Definition and Calculation of Income) Regulations 2002 s. 3" + ) def formula(benunit, period, parameters): TC = parameters(period).gov.dwp.tax_credits diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/child_element/disability/severe_disability/uc_individual_severely_disabled_child_element.py b/policyengine_uk/variables/gov/dwp/universal_credit/child_element/disability/severe_disability/uc_individual_severely_disabled_child_element.py index 1064003b4..aa78f5fd4 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/child_element/disability/severe_disability/uc_individual_severely_disabled_child_element.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/child_element/disability/severe_disability/uc_individual_severely_disabled_child_element.py @@ -10,8 +10,6 @@ class uc_individual_severely_disabled_child_element(Variable): defined_for = "is_severely_disabled_for_benefits" def formula(person, period, parameters): - p = parameters( - period - ).gov.dwp.universal_credit.elements.child.severely_disabled + p = parameters(period).gov.dwp.universal_credit.elements.child.severely_disabled child = person("is_child", period) return (child * p.amount) * MONTHS_IN_YEAR diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/child_element/uc_individual_child_element.py b/policyengine_uk/variables/gov/dwp/universal_credit/child_element/uc_individual_child_element.py index 67378fb9b..2689be9b9 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/child_element/uc_individual_child_element.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/child_element/uc_individual_child_element.py @@ -12,24 +12,18 @@ class uc_individual_child_element(Variable): def formula(person, period, parameters): p = parameters(period).gov.dwp.universal_credit.elements.child child_index = person("child_index", period) - born_before_limit = person( - "uc_is_child_born_before_child_limit", period - ) - child_limit_applying = where( - ~born_before_limit, p.limit.child_count, inf - ) - is_eligible = (child_index != -1) & ( - child_index <= child_limit_applying - ) + born_before_limit = person("uc_is_child_born_before_child_limit", period) + child_limit_applying = where(~born_before_limit, p.limit.child_count, inf) + is_eligible = (child_index != -1) & (child_index <= child_limit_applying) # Reform proposal - age_exemption = parameters.gov.contrib.two_child_limit.age_exemption.universal_credit( - period + age_exemption = ( + parameters.gov.contrib.two_child_limit.age_exemption.universal_credit( + period + ) ) if age_exemption > 0: - is_exempt = person.benunit.any( - person("age", period) < age_exemption - ) + is_exempt = person.benunit.any(person("age", period) < age_exemption) born_before_limit = is_exempt return ( diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_element.py b/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_element.py index f8e847239..f8d7ce661 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_element.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_element.py @@ -11,9 +11,7 @@ class uc_childcare_element(Variable): def formula(benunit, period, parameters): p = parameters(period).gov.dwp.universal_credit.elements.childcare - eligible_childcare_expenses = add( - benunit, period, ["childcare_expenses"] - ) + eligible_childcare_expenses = add(benunit, period, ["childcare_expenses"]) covered_expenses = eligible_childcare_expenses * p.coverage_rate max_childcare = benunit("uc_maximum_childcare_element_amount", period) return min_(max_childcare, covered_expenses) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_work_condition.py b/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_work_condition.py index e2bf83881..125198170 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_work_condition.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_childcare_work_condition.py @@ -6,9 +6,7 @@ class uc_childcare_work_condition(Variable): entity = BenUnit label = "Meets Universal Credit childcare work condition" definition_period = YEAR - reference = ( - "https://www.legislation.gov.uk/uksi/2013/376/regulation/32/2020-04-06" - ) + reference = "https://www.legislation.gov.uk/uksi/2013/376/regulation/32/2020-04-06" def formula(benunit, period, parameters): person = benunit.members diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_eligible_children.py b/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_eligible_children.py index ad231c35b..505083e23 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_eligible_children.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/childcare_element/uc_eligible_children.py @@ -9,7 +9,5 @@ class uc_childcare_element_eligible_children(Variable): definition_period = YEAR def formula(benunit, period, parameters): - eligible_child = ( - benunit.members("uc_individual_child_element", period) > 0 - ) + eligible_child = benunit.members("uc_individual_child_element", period) > 0 return benunit.sum(eligible_child) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/disability_element/limited_work_ability/uc_LCWRA_element.py b/policyengine_uk/variables/gov/dwp/universal_credit/disability_element/limited_work_ability/uc_LCWRA_element.py index b966c3c56..6460d3aaa 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/disability_element/limited_work_ability/uc_LCWRA_element.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/disability_element/limited_work_ability/uc_LCWRA_element.py @@ -4,16 +4,12 @@ class uc_LCWRA_element(Variable): value_type = float entity = BenUnit - label = ( - "Universal Credit limited capability for work-related-activity element" - ) + label = "Universal Credit limited capability for work-related-activity element" definition_period = YEAR unit = GBP def formula(benunit, period, parameters): p = parameters(period).gov.dwp.universal_credit.elements.disabled - limited_capability = benunit.members( - "uc_limited_capability_for_WRA", period - ) + limited_capability = benunit.members("uc_limited_capability_for_WRA", period) person_amounts = limited_capability * p.amount return benunit.sum(person_amounts) * MONTHS_IN_YEAR diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_applies.py b/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_applies.py index 0b706f353..89874240e 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_applies.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_applies.py @@ -5,10 +5,10 @@ class uc_mif_applies(Variable): value_type = bool entity = Person label = "Universal Credit minimum income floor applies" - documentation = "Whether the Minimum Income Floor should be used to determine UC entitlement" - reference = ( - "https://www.legislation.gov.uk/uksi/2013/376/regulation/62/2021-04-06" + documentation = ( + "Whether the Minimum Income Floor should be used to determine UC entitlement" ) + reference = "https://www.legislation.gov.uk/uksi/2013/376/regulation/62/2021-04-06" definition_period = YEAR def formula(person, period, parameters): diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_capped_earned_income.py b/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_capped_earned_income.py index a266908d4..03c7deb25 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_capped_earned_income.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/income/income_floor/uc_mif_capped_earned_income.py @@ -5,9 +5,7 @@ class uc_mif_capped_earned_income(Variable): value_type = float entity = Person label = "Universal Credit gross earned income (incl. MIF)" - documentation = ( - "Gross earned income for UC, with MIF applied where applicable" - ) + documentation = "Gross earned income for UC, with MIF applied where applicable" definition_period = YEAR unit = GBP diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/income/uc_is_in_startup_period.py b/policyengine_uk/variables/gov/dwp/universal_credit/income/uc_is_in_startup_period.py index 05807fa26..cba26efca 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/income/uc_is_in_startup_period.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/income/uc_is_in_startup_period.py @@ -5,8 +5,6 @@ class uc_is_in_startup_period(Variable): value_type = bool entity = Person label = "In a start-up period for the Universal Credit" - documentation = ( - "Whether this person is in a 'start-up' period for Universal Credit" - ) + documentation = "Whether this person is in a 'start-up' period for Universal Credit" definition_period = YEAR default_value = False diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/standard_allowance/uc_standard_allowance_claimant_type.py b/policyengine_uk/variables/gov/dwp/universal_credit/standard_allowance/uc_standard_allowance_claimant_type.py index 95bfbc3ab..88a246f78 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/standard_allowance/uc_standard_allowance_claimant_type.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/standard_allowance/uc_standard_allowance_claimant_type.py @@ -14,19 +14,13 @@ class uc_standard_allowance_claimant_type(Variable): default_value = UCClaimantType.SINGLE_YOUNG entity = BenUnit label = "Universal Credit claimant type" - documentation = ( - "The category of the UC claimant, assuming their eligibilty to UC" - ) + documentation = "The category of the UC claimant, assuming their eligibilty to UC" definition_period = YEAR def formula(benunit, period, parameters): is_single = benunit("is_single", period) - p = parameters( - period - ).gov.dwp.universal_credit.standard_allowance.claimant_type - any_over_25 = ( - benunit("eldest_adult_age", period.this_year) >= p.age_threshold - ) + p = parameters(period).gov.dwp.universal_credit.standard_allowance.claimant_type + any_over_25 = benunit("eldest_adult_age", period.this_year) >= p.age_threshold return select( [ is_single & ~any_over_25, diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_maximum_amount.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_maximum_amount.py index fc0a8cfc1..31888aa9c 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_maximum_amount.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_maximum_amount.py @@ -5,9 +5,7 @@ class uc_maximum_amount(Variable): value_type = float entity = BenUnit label = "maximum Universal Credit amount" - documentation = ( - "This is your total entitlement, before reduction due to income." - ) + documentation = "This is your total entitlement, before reduction due to income." definition_period = YEAR unit = GBP defined_for = "is_uc_eligible" diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/universal_credit.py b/policyengine_uk/variables/gov/dwp/universal_credit/universal_credit.py index ceed86f85..41fdd777a 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/universal_credit.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/universal_credit.py @@ -10,8 +10,6 @@ class universal_credit(Variable): defined_for = "would_claim_uc" def formula(benunit, period, parameters): - uc_max_entitlement = benunit( - "universal_credit_pre_benefit_cap", period - ) + uc_max_entitlement = benunit("universal_credit_pre_benefit_cap", period) benefit_cap_reduction = benunit("benefit_cap_reduction", period) return max_(uc_max_entitlement - benefit_cap_reduction, 0) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/is_uc_work_allowance_eligible.py b/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/is_uc_work_allowance_eligible.py index bd86c0bb6..8489bc664 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/is_uc_work_allowance_eligible.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/is_uc_work_allowance_eligible.py @@ -9,8 +9,6 @@ class is_uc_work_allowance_eligible(Variable): def formula(benunit, period, parameters): person = benunit.members - has_LCWRA = benunit.any( - person("uc_limited_capability_for_WRA", period) - ) + has_LCWRA = benunit.any(person("uc_limited_capability_for_WRA", period)) has_children = benunit.any(person("is_child", period)) return has_LCWRA | has_children diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/uc_work_allowance.py b/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/uc_work_allowance.py index 999ed6f4d..474abe7fe 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/uc_work_allowance.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/work_allowance/uc_work_allowance.py @@ -10,9 +10,7 @@ class uc_work_allowance(Variable): defined_for = "is_uc_work_allowance_eligible" def formula(benunit, period, parameters): - p = parameters( - period - ).gov.dwp.universal_credit.means_test.work_allowance + p = parameters(period).gov.dwp.universal_credit.means_test.work_allowance housing = benunit("uc_housing_costs_element", period) monthly_allowance = where( housing > 0, diff --git a/policyengine_uk/variables/gov/dwp/winter_fuel_allowance.py b/policyengine_uk/variables/gov/dwp/winter_fuel_allowance.py index 0c23d68e7..84d34f9df 100644 --- a/policyengine_uk/variables/gov/dwp/winter_fuel_allowance.py +++ b/policyengine_uk/variables/gov/dwp/winter_fuel_allowance.py @@ -9,9 +9,7 @@ class winter_fuel_allowance(Variable): unit = GBP def formula(household, period, parameters): - in_scotland = ( - household("country", period).decode_to_str() == "SCOTLAND" - ) + in_scotland = household("country", period).decode_to_str() == "SCOTLAND" age = household.members("age", period) is_SP_age = household.members("is_SP_age", period) wfp = parameters(period).gov.dwp.winter_fuel_payment @@ -45,9 +43,7 @@ def formula(household, period, parameters): ) meets_mtb_requirement = ( - on_mtb - | (not wfp.eligibility.require_benefits) - | meets_income_passport + on_mtb | (not wfp.eligibility.require_benefits) | meets_income_passport ) meets_spa_requirement = household.any(is_SP_age) | ( not wfp.eligibility.state_pension_age_requirement @@ -56,9 +52,7 @@ def formula(household, period, parameters): age >= wfp.eligibility.higher_age_requirement ) qualifies_for_higher = ( - meets_mtb_requirement - & meets_spa_requirement - & meets_higher_age_requirement + meets_mtb_requirement & meets_spa_requirement & meets_higher_age_requirement ) qualifies_for_lower = ( meets_mtb_requirement diff --git a/policyengine_uk/variables/gov/dwp/working_tax_credit_pre_minimum.py b/policyengine_uk/variables/gov/dwp/working_tax_credit_pre_minimum.py index fdea721f5..5d20a65b3 100644 --- a/policyengine_uk/variables/gov/dwp/working_tax_credit_pre_minimum.py +++ b/policyengine_uk/variables/gov/dwp/working_tax_credit_pre_minimum.py @@ -5,9 +5,7 @@ class working_tax_credit_pre_minimum(Variable): value_type = float entity = BenUnit label = "Working Tax Credit pre-minimum" - documentation = ( - "Working Tax Credit amount before the minimum tax credit is applied" - ) + documentation = "Working Tax Credit amount before the minimum tax credit is applied" defined_for = "would_claim_WTC" definition_period = YEAR unit = GBP diff --git a/policyengine_uk/variables/gov/dwp/would_claim_CTC.py b/policyengine_uk/variables/gov/dwp/would_claim_CTC.py index fea0e73e8..20334e827 100644 --- a/policyengine_uk/variables/gov/dwp/would_claim_CTC.py +++ b/policyengine_uk/variables/gov/dwp/would_claim_CTC.py @@ -5,14 +5,10 @@ class would_claim_CTC(Variable): value_type = bool entity = BenUnit label = "Would claim Child Tax Credit" - documentation = ( - "Whether this family would claim Child Tax Credit if eligible" - ) + documentation = "Whether this family would claim Child Tax Credit if eligible" definition_period = YEAR def formula(benunit, period, parameters): reported_ctc = add(benunit, period, ["child_tax_credit_reported"]) > 0 - claims_all_entitled_benefits = benunit( - "claims_all_entitled_benefits", period - ) + claims_all_entitled_benefits = benunit("claims_all_entitled_benefits", period) return reported_ctc | claims_all_entitled_benefits diff --git a/policyengine_uk/variables/gov/dwp/would_claim_IS.py b/policyengine_uk/variables/gov/dwp/would_claim_IS.py index 50c04c601..f2bed79a2 100644 --- a/policyengine_uk/variables/gov/dwp/would_claim_IS.py +++ b/policyengine_uk/variables/gov/dwp/would_claim_IS.py @@ -5,14 +5,10 @@ class would_claim_IS(Variable): value_type = bool entity = BenUnit label = "Would claim Income Support" - documentation = ( - "Whether this family would claim Income Support if eligible" - ) + documentation = "Whether this family would claim Income Support if eligible" definition_period = YEAR def formula(benunit, period, parameters): reported_is = add(benunit, period, ["income_support_reported"]) > 0 - claims_all_entitled_benefits = benunit( - "claims_all_entitled_benefits", period - ) + claims_all_entitled_benefits = benunit("claims_all_entitled_benefits", period) return reported_is | claims_all_entitled_benefits diff --git a/policyengine_uk/variables/gov/dwp/would_claim_WTC.py b/policyengine_uk/variables/gov/dwp/would_claim_WTC.py index f86f58654..4b790e76d 100644 --- a/policyengine_uk/variables/gov/dwp/would_claim_WTC.py +++ b/policyengine_uk/variables/gov/dwp/would_claim_WTC.py @@ -5,16 +5,10 @@ class would_claim_WTC(Variable): value_type = bool entity = BenUnit label = "Would claim Working Tax Credit" - documentation = ( - "Whether this family would claim Working Tax Credit if eligible" - ) + documentation = "Whether this family would claim Working Tax Credit if eligible" definition_period = YEAR def formula(benunit, period, parameters): - reported_wtc = ( - add(benunit, period, ["working_tax_credit_reported"]) > 0 - ) - claims_all_entitled_benefits = benunit( - "claims_all_entitled_benefits", period - ) + reported_wtc = add(benunit, period, ["working_tax_credit_reported"]) > 0 + claims_all_entitled_benefits = benunit("claims_all_entitled_benefits", period) return reported_wtc | claims_all_entitled_benefits diff --git a/policyengine_uk/variables/gov/gov_tax.py b/policyengine_uk/variables/gov/gov_tax.py index 131cf8ef7..a027fd287 100644 --- a/policyengine_uk/variables/gov/gov_tax.py +++ b/policyengine_uk/variables/gov/gov_tax.py @@ -3,9 +3,7 @@ class gov_tax(Variable): label = "government tax revenue" - documentation = ( - "Government tax revenue impact in respect of this household." - ) + documentation = "Government tax revenue impact in respect of this household." entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/hmrc/baseline_business_rates.py b/policyengine_uk/variables/gov/hmrc/baseline_business_rates.py index b426300c2..c18efdc99 100644 --- a/policyengine_uk/variables/gov/hmrc/baseline_business_rates.py +++ b/policyengine_uk/variables/gov/hmrc/baseline_business_rates.py @@ -3,9 +3,7 @@ class baseline_business_rates(Variable): label = "Baseline business rates incidence" - documentation = ( - "Total incidence from business rates exposure in the baseline" - ) + documentation = "Total incidence from business rates exposure in the baseline" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/hmrc/baseline_vat.py b/policyengine_uk/variables/gov/hmrc/baseline_vat.py index 04da34bf1..4343701b5 100644 --- a/policyengine_uk/variables/gov/hmrc/baseline_vat.py +++ b/policyengine_uk/variables/gov/hmrc/baseline_vat.py @@ -10,9 +10,7 @@ class baseline_vat(Variable): def formula(household, period, parameters): full_rate_consumption = household("full_rate_vat_consumption", period) - reduced_rate_consumption = household( - "reduced_rate_vat_consumption", period - ) + reduced_rate_consumption = household("reduced_rate_vat_consumption", period) p = parameters(period).baseline.gov raw_vat = ( full_rate_consumption * p.hmrc.vat.standard_rate diff --git a/policyengine_uk/variables/gov/hmrc/business_rates.py b/policyengine_uk/variables/gov/hmrc/business_rates.py index 883914522..af0c5c045 100644 --- a/policyengine_uk/variables/gov/hmrc/business_rates.py +++ b/policyengine_uk/variables/gov/hmrc/business_rates.py @@ -6,7 +6,9 @@ class business_rates(Variable): label = "Business rates incidence" - documentation = "Total incidence from exposure to business rates via corporate shareholdings" + documentation = ( + "Total incidence from exposure to business rates via corporate shareholdings" + ) entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_behavioural_response.py b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_behavioural_response.py index b56a7cd14..40829f155 100644 --- a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_behavioural_response.py +++ b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_behavioural_response.py @@ -14,12 +14,7 @@ def formula(person, period, parameters): if simulation.baseline is None: return 0 - if ( - parameters( - period - ).gov.simulation.capital_gains_responses.elasticity - == 0 - ): + if parameters(period).gov.simulation.capital_gains_responses.elasticity == 0: return 0 capital_gains = person("capital_gains_before_response", period) diff --git a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_tax.py b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_tax.py index dedcb6d9b..0538256d7 100644 --- a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_tax.py +++ b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/capital_gains_tax.py @@ -21,9 +21,7 @@ def formula(person, period, parameters): basic_rate_limit = it.rates.uk.thresholds[1] remaining_basic_rate_band = max_(basic_rate_limit - ani, 0) - basic_rate_applicable_cg = min_( - gains_less_aea, remaining_basic_rate_band - ) + basic_rate_applicable_cg = min_(gains_less_aea, remaining_basic_rate_band) higher_and_add_rate_applicable_cg = max_( gains_less_aea - remaining_basic_rate_band, 0 ) diff --git a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/marginal_tax_rate_on_capital_gains.py b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/marginal_tax_rate_on_capital_gains.py index 792d46dda..e011505a3 100644 --- a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/marginal_tax_rate_on_capital_gains.py +++ b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/marginal_tax_rate_on_capital_gains.py @@ -4,7 +4,9 @@ class marginal_tax_rate_on_capital_gains(Variable): label = "capital gains marginal tax rate" - documentation = "Percent of marginal capital gains that do not increase household net income." + documentation = ( + "Percent of marginal capital gains that do not increase household net income." + ) entity = Person definition_period = YEAR value_type = float @@ -16,14 +18,10 @@ def formula(person, period, parameters): DELTA = 1_000 adult_index_values = person("adult_index_cg", period) for adult_index in [1, 2]: - alt_simulation = simulation.get_branch( - f"adult_{adult_index}_cg_rise" - ) + alt_simulation = simulation.get_branch(f"adult_{adult_index}_cg_rise") mask = adult_index_values == adult_index for variable in simulation.tax_benefit_system.variables: - variable_data = simulation.tax_benefit_system.variables[ - variable - ] + variable_data = simulation.tax_benefit_system.variables[variable] if ( variable not in simulation.input_variables and not variable_data.is_input_variable() @@ -35,15 +33,11 @@ def formula(person, period, parameters): person("capital_gains", period) + mask * DELTA, ) alt_person = alt_simulation.person - household_net_income = person.household( - "household_net_income", period - ) + household_net_income = person.household("household_net_income", period) household_net_income_higher_earnings = alt_person.household( "household_net_income", period ) - increase = ( - household_net_income_higher_earnings - household_net_income - ) + increase = household_net_income_higher_earnings - household_net_income mtr_values += where(mask, 1 - increase / DELTA, 0) del simulation.branches[f"adult_{adult_index}_cg_rise"] diff --git a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/relative_capital_gains_mtr_change.py b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/relative_capital_gains_mtr_change.py index 3028e3e70..4cef0119d 100644 --- a/policyengine_uk/variables/gov/hmrc/capital_gains_tax/relative_capital_gains_mtr_change.py +++ b/policyengine_uk/variables/gov/hmrc/capital_gains_tax/relative_capital_gains_mtr_change.py @@ -28,12 +28,8 @@ def formula(person, period, parameters): period, person("capital_gains_before_response", period), ) - baseline_mtr = baseline_person( - "marginal_tax_rate_on_capital_gains", period - ) - del simulation.branches["baseline"].branches[ - "baseline_cgr_measurement" - ] + baseline_mtr = baseline_person("marginal_tax_rate_on_capital_gains", period) + del simulation.branches["baseline"].branches["baseline_cgr_measurement"] measurement_branch = simulation.get_branch("cgr_measurement") measurement_branch.tax_benefit_system.neutralize_variable( @@ -45,9 +41,7 @@ def formula(person, period, parameters): person("capital_gains_before_response", period), ) measurement_person = measurement_branch.populations["person"] - reform_mtr = measurement_person( - "marginal_tax_rate_on_capital_gains", period - ) + reform_mtr = measurement_person("marginal_tax_rate_on_capital_gains", period) del simulation.branches["cgr_measurement"] # Handle zeros in tax rates to prevent log(0) diff --git a/policyengine_uk/variables/gov/hmrc/child_benefit_less_tax_charge.py b/policyengine_uk/variables/gov/hmrc/child_benefit_less_tax_charge.py index 491f0adfd..a7b1da0c7 100644 --- a/policyengine_uk/variables/gov/hmrc/child_benefit_less_tax_charge.py +++ b/policyengine_uk/variables/gov/hmrc/child_benefit_less_tax_charge.py @@ -3,9 +3,7 @@ class child_benefit_less_tax_charge(Variable): label = "Child Benefit (less tax charge)" - documentation = ( - "Child Benefit, minus the Child Benefit High-Income Tax Charge" - ) + documentation = "Child Benefit, minus the Child Benefit High-Income Tax Charge" entity = BenUnit definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/hmrc/child_benefit_respective_amount.py b/policyengine_uk/variables/gov/hmrc/child_benefit_respective_amount.py index 810cd3b0e..2213b9277 100644 --- a/policyengine_uk/variables/gov/hmrc/child_benefit_respective_amount.py +++ b/policyengine_uk/variables/gov/hmrc/child_benefit_respective_amount.py @@ -20,12 +20,9 @@ def formula(person, period, parameters): period ).gov.contrib.ubi_center.basic_income.interactions.withdraw_cb: eligible &= ( - person.benunit.sum(person("basic_income", period.this_year)) - == 0 + person.benunit.sum(person("basic_income", period.this_year)) == 0 ) is_eldest = person("is_eldest_child", period.this_year) child_benefit = parameters(period).gov.hmrc.child_benefit.amount - amount = where( - is_eldest, child_benefit.eldest, child_benefit.additional - ) + amount = where(is_eldest, child_benefit.eldest, child_benefit.additional) return eligible * amount * WEEKS_IN_YEAR / MONTHS_IN_YEAR diff --git a/policyengine_uk/variables/gov/hmrc/corporate_sdlt.py b/policyengine_uk/variables/gov/hmrc/corporate_sdlt.py index 93e3a121f..91e2b6848 100644 --- a/policyengine_uk/variables/gov/hmrc/corporate_sdlt.py +++ b/policyengine_uk/variables/gov/hmrc/corporate_sdlt.py @@ -3,9 +3,7 @@ class corporate_sdlt(Variable): label = "Stamp Duty (corporations)" - documentation = ( - "Stamp Duty paid by corporations, incident on this household" - ) + documentation = "Stamp Duty paid by corporations, incident on this household" entity = Household definition_period = YEAR value_type = float @@ -14,6 +12,5 @@ class corporate_sdlt(Variable): def formula(household, period, parameters): sd = parameters(period).gov.hmrc.stamp_duty.statistics return household("shareholding", period) * ( - sd.residential.corporate.revenue - + sd.non_residential.corporate.revenue + sd.residential.corporate.revenue + sd.non_residential.corporate.revenue ) diff --git a/policyengine_uk/variables/gov/hmrc/fuel_duty/fuel_duty.py b/policyengine_uk/variables/gov/hmrc/fuel_duty/fuel_duty.py index b0806780c..8d07d015e 100644 --- a/policyengine_uk/variables/gov/hmrc/fuel_duty/fuel_duty.py +++ b/policyengine_uk/variables/gov/hmrc/fuel_duty/fuel_duty.py @@ -13,12 +13,8 @@ class fuel_duty(Variable): def formula(household, period, parameters): fd = parameters(period).gov.hmrc.fuel_duty - petrol_litres = ( - household("petrol_litres", period.this_year) / MONTHS_IN_YEAR - ) - diesel_litres = ( - household("diesel_litres", period.this_year) / MONTHS_IN_YEAR - ) + petrol_litres = household("petrol_litres", period.this_year) / MONTHS_IN_YEAR + diesel_litres = household("diesel_litres", period.this_year) / MONTHS_IN_YEAR return ( fd.petrol_and_diesel * (petrol_litres + diesel_litres) diff --git a/policyengine_uk/variables/gov/hmrc/household_tax.py b/policyengine_uk/variables/gov/hmrc/household_tax.py index 5655b2477..1148868d9 100644 --- a/policyengine_uk/variables/gov/hmrc/household_tax.py +++ b/policyengine_uk/variables/gov/hmrc/household_tax.py @@ -39,11 +39,7 @@ def formula(household, period, parameters): return add( household, period, - [ - tax - for tax in household_tax.adds - if tax not in ["council_tax"] - ], + [tax for tax in household_tax.adds if tax not in ["council_tax"]], ) else: return add(household, period, household_tax.adds) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/capped_mcad.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/capped_mcad.py index 6df277172..b4d73c2a3 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/capped_mcad.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/capped_mcad.py @@ -9,9 +9,7 @@ class capped_mcad(Variable): unit = GBP def formula(person, period, parameters): - capping_value = add( - person, period, ["income_tax_pre_charges", "CB_HITC"] - ) + capping_value = add(person, period, ["income_tax_pre_charges", "CB_HITC"]) return min_( person("married_couples_allowance_deduction", period), capping_value, diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/dividend_allowance.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/dividend_allowance.py index adb6b5c1b..0f90318f5 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/dividend_allowance.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/dividend_allowance.py @@ -10,6 +10,4 @@ class dividend_allowance(Variable): unit = GBP def formula(person, period, parameters): - return parameters( - period - ).gov.hmrc.income_tax.allowances.dividend_allowance + return parameters(period).gov.hmrc.income_tax.allowances.dividend_allowance diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/marriage_allowance.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/marriage_allowance.py index 3408b320a..c910c0f25 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/marriage_allowance.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/marriage_allowance.py @@ -30,9 +30,7 @@ def formula(person, period, parameters): eligible = married & person( "meets_marriage_allowance_income_conditions", period ) - transferable_amount = person( - "partners_unused_personal_allowance", period - ) + transferable_amount = person("partners_unused_personal_allowance", period) allowances = parameters(period).gov.hmrc.income_tax.allowances capped_percentage = allowances.marriage_allowance.max max_amount = allowances.personal_allowance.amount * capped_percentage diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/partners_unused_personal_allowance.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/partners_unused_personal_allowance.py index b0272068a..e9c8d41e8 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/partners_unused_personal_allowance.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/partners_unused_personal_allowance.py @@ -4,7 +4,9 @@ class partners_unused_personal_allowance(Variable): label = "Partner's unused personal allowance" - documentation = "The personal tax allowance not used by this person's partner, if they exist" + documentation = ( + "The personal tax allowance not used by this person's partner, if they exist" + ) entity = Person definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/pension_annual_allowance.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/pension_annual_allowance.py index 0c877005d..c066e301c 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/pension_annual_allowance.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/pension_annual_allowance.py @@ -9,9 +9,7 @@ class pension_annual_allowance(Variable): unit = GBP def formula(person, period, parameters): - allowance = parameters( - period - ).gov.hmrc.income_tax.allowances.annual_allowance + allowance = parameters(period).gov.hmrc.income_tax.allowances.annual_allowance ANI = person("adjusted_net_income", period) reduction = max_(0, ANI - allowance.taper) * allowance.reduction_rate return max_(allowance.minimum, allowance.default - reduction) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/property_allowance.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/property_allowance.py index 6d8d3aeaa..160e729c9 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/property_allowance.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/property_allowance.py @@ -10,6 +10,4 @@ class property_allowance(Variable): unit = GBP def formula(person, period, parameters): - return parameters( - period - ).gov.hmrc.income_tax.allowances.property_allowance + return parameters(period).gov.hmrc.income_tax.allowances.property_allowance diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_earned_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_earned_income.py index c72826c0c..bcdd36dcd 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_earned_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_earned_income.py @@ -15,9 +15,9 @@ def formula(person, period, parameters): all_allowances = person("allowances", period) all_income = person("adjusted_net_income", period) - excluded_income = person( - "taxable_savings_interest_income", period - ) + person("taxable_dividend_income", period) + excluded_income = person("taxable_savings_interest_income", period) + person( + "taxable_dividend_income", period + ) earned_income = all_income - excluded_income return where( diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_savings_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_savings_income.py index 926765a83..ba3469a3e 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_savings_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/received_allowances/received_allowances_savings_income.py @@ -14,9 +14,7 @@ def formula(person, period, parameters): received_allowances_earned_income = person( "received_allowances_earned_income", period ) - remaining_allowance = ( - all_allowances - received_allowances_earned_income - ) + remaining_allowance = all_allowances - received_allowances_earned_income savings_income = person("taxable_savings_interest_income", period) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/trading_allowance.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/trading_allowance.py index 96027b288..8dfef0108 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/trading_allowance.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/trading_allowance.py @@ -10,6 +10,4 @@ class trading_allowance(Variable): unit = GBP def formula(person, period, parameters): - return parameters( - period - ).gov.hmrc.income_tax.allowances.trading_allowance + return parameters(period).gov.hmrc.income_tax.allowances.trading_allowance diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_dividend_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_dividend_income.py index 752040c0b..9fb1e7ed6 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_dividend_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_dividend_income.py @@ -15,6 +15,5 @@ class taxable_dividend_income(Variable): def formula(person, period, parameters): return max_( 0, - person("dividend_income", period) - - person("deficiency_relief", period), + person("dividend_income", period) - person("deficiency_relief", period), ) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_property_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_property_income.py index dffe186de..f2798b857 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_property_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bases/taxable_property_income.py @@ -15,6 +15,5 @@ class taxable_property_income(Variable): def formula(person, period, parameters): return max_( 0, - person("property_income", period) - - person("property_allowance", period), + person("property_income", period) - person("property_allowance", period), ) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/add_rate_earned_income_tax.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/add_rate_earned_income_tax.py index 6de13e6c8..5ed659685 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/add_rate_earned_income_tax.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/add_rate_earned_income_tax.py @@ -14,6 +14,4 @@ class add_rate_earned_income_tax(Variable): def formula(person, period, parameters): amount = person("add_rate_earned_income", period) - return ( - parameters(period).gov.hmrc.income_tax.rates.uk.rates[2] * amount - ) + return parameters(period).gov.hmrc.income_tax.rates.uk.rates[2] * amount diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/basic_rate_earned_income_tax.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/basic_rate_earned_income_tax.py index 05f09d412..8adebbb13 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/basic_rate_earned_income_tax.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/basic_rate_earned_income_tax.py @@ -14,6 +14,4 @@ class basic_rate_earned_income_tax(Variable): def formula(person, period, parameters): amount = person("basic_rate_earned_income", period) - return ( - parameters(period).gov.hmrc.income_tax.rates.uk.rates[0] * amount - ) + return parameters(period).gov.hmrc.income_tax.rates.uk.rates[0] * amount diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/higher_rate_earned_income_tax.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/higher_rate_earned_income_tax.py index 1676af503..d55c34631 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/higher_rate_earned_income_tax.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/higher_rate_earned_income_tax.py @@ -14,6 +14,4 @@ class higher_rate_earned_income_tax(Variable): def formula(person, period, parameters): amount = person("higher_rate_earned_income", period) - return ( - parameters(period).gov.hmrc.income_tax.rates.uk.rates[1] * amount - ) + return parameters(period).gov.hmrc.income_tax.rates.uk.rates[1] * amount diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/tax_band.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/tax_band.py index 1ab44af1c..7a67966c9 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/tax_band.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_liability/tax_band.py @@ -47,10 +47,7 @@ def formula_2017_04_06(person, period, parameters): default=TaxBand.ADDITIONAL, ) scottish_band = select( - [ - income < threshold - for threshold in rates.scotland.rates.thresholds[:3] - ], + [income < threshold for threshold in rates.scotland.rates.thresholds[:3]], [TaxBand.NONE, TaxBand.BASIC, TaxBand.HIGHER], default=TaxBand.ADDITIONAL, ) @@ -68,10 +65,7 @@ def formula_2018_06_01(person, period, parameters): default=TaxBand.ADDITIONAL, ) scottish_band = select( - [ - income < threshold - for threshold in rates.scotland.rates.thresholds[:5] - ], + [income < threshold for threshold in rates.scotland.rates.thresholds[:5]], [ TaxBand.NONE, TaxBand.STARTER, diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/add_rate_savings_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/add_rate_savings_income.py index e1a215307..9ec04f79c 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/add_rate_savings_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/add_rate_savings_income.py @@ -26,8 +26,7 @@ def formula(person, period, parameters): ) savings_income_less_deductions = max_( 0, - person("taxable_savings_interest_income", period) - - savings_deductions, + person("taxable_savings_interest_income", period) - savings_deductions, ) add_rate_amount_with = clip( other_income + savings_income_less_deductions, diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income.py index 49d196527..bfd01b794 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income.py @@ -26,15 +26,12 @@ def formula(person, period, parameters): ) savings_income_less_deductions = max_( 0, - person("taxable_savings_interest_income", period) - - savings_deductions, + person("taxable_savings_interest_income", period) - savings_deductions, ) basic_rate_amount_with = clip( other_income + savings_income_less_deductions, thresholds[0], thresholds[1], ) - basic_rate_amount_without = clip( - other_income, thresholds[0], thresholds[1] - ) + basic_rate_amount_without = clip(other_income, thresholds[0], thresholds[1]) return max_(0, basic_rate_amount_with - basic_rate_amount_without) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income_pre_starter.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income_pre_starter.py index 46276a21c..63760e20a 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income_pre_starter.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/basic_rate_savings_income_pre_starter.py @@ -14,9 +14,7 @@ class basic_rate_savings_income_pre_starter(Variable): def formula(person, period, parameters): thresholds = parameters(period).gov.hmrc.income_tax.rates.uk.thresholds - savings_income_total = person( - "taxable_savings_interest_income", period - ) + savings_income_total = person("taxable_savings_interest_income", period) savings_allowance = person("savings_allowance", period) savings_income = max_(0, savings_income_total - savings_allowance) other_income = person("earned_taxable_income", period) @@ -28,6 +26,4 @@ def formula(person, period, parameters): basic_rate_amount_without_savings = clip( other_income, thresholds[0], thresholds[1] ) - return ( - basic_rate_amount_with_savings - basic_rate_amount_without_savings - ) + return basic_rate_amount_with_savings - basic_rate_amount_without_savings diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/higher_rate_savings_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/higher_rate_savings_income.py index 45fdaab49..ee50f48c5 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/higher_rate_savings_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/higher_rate_savings_income.py @@ -26,15 +26,12 @@ def formula(person, period, parameters): ) savings_income_less_deductions = max_( 0, - person("taxable_savings_interest_income", period) - - savings_deductions, + person("taxable_savings_interest_income", period) - savings_deductions, ) higher_rate_amount_with = clip( other_income + savings_income_less_deductions, thresholds[1], thresholds[2], ) - higher_rate_amount_without = clip( - other_income, thresholds[1], thresholds[2] - ) + higher_rate_amount_without = clip(other_income, thresholds[1], thresholds[2]) return max_(0, higher_rate_amount_with - higher_rate_amount_without) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/savings_starter_rate_income.py b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/savings_starter_rate_income.py index ddc197dcf..8f76e76a3 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/savings_starter_rate_income.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/bracketized_savings_income/savings_starter_rate_income.py @@ -29,9 +29,7 @@ def formula(person, period, parameters): starter_rate_taper_start = max_personal_allowance + limit - savings_income = person( - "basic_rate_savings_income_pre_starter", period - ) + savings_income = person("basic_rate_savings_income_pre_starter", period) earned_taxable_income = person("earned_taxable_income", period) dividend_income = person("taxable_dividend_income", period) non_savings_income = earned_taxable_income + dividend_income diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/deductions/employment_expenses.py b/policyengine_uk/variables/gov/hmrc/income_tax/deductions/employment_expenses.py index c54688064..cffac78c1 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/deductions/employment_expenses.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/deductions/employment_expenses.py @@ -4,9 +4,7 @@ class employment_expenses(Variable): value_type = float entity = Person - label = ( - "Cost of expenses necessarily incurred and reimbursed by employment" - ) + label = "Cost of expenses necessarily incurred and reimbursed by employment" definition_period = YEAR reference = dict( title="Income Tax Act (Earnings and Pensions) Act 2003 s. 333", diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/liability/dividend_income_tax.py b/policyengine_uk/variables/gov/hmrc/income_tax/liability/dividend_income_tax.py index 2fdc3d060..a1a8e4ee0 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/liability/dividend_income_tax.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/liability/dividend_income_tax.py @@ -18,8 +18,6 @@ def formula(person, period, parameters): "taxed_savings_income", period ) taxable_dividends = person("taxed_dividend_income", period) - tax_with_dividends = rates.dividends.calc( - other_income + taxable_dividends - ) + tax_with_dividends = rates.dividends.calc(other_income + taxable_dividends) tax_without_dividends = rates.dividends.calc(other_income) return max_(0, tax_with_dividends - tax_without_dividends) diff --git a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_additional.py b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_additional.py index eb23397d3..6f8dffd2c 100644 --- a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_additional.py +++ b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_additional.py @@ -13,11 +13,7 @@ def formula(person, period, parameters): income = person("ni_class_1_income", period) parameters = parameters(period).gov.hmrc.national_insurance.class_1 upper_earnings_limit = ( - parameters.thresholds.upper_earnings_limit - * WEEKS_IN_YEAR - / MONTHS_IN_YEAR + parameters.thresholds.upper_earnings_limit * WEEKS_IN_YEAR / MONTHS_IN_YEAR ) upper_earnings_limit_income = max_(income - upper_earnings_limit, 0) - return ( - parameters.rates.employee.additional * upper_earnings_limit_income - ) + return parameters.rates.employee.additional * upper_earnings_limit_income diff --git a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_primary.py b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_primary.py index e54c987e1..69b5db498 100644 --- a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_primary.py +++ b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employee_primary.py @@ -15,14 +15,10 @@ def formula(person, period, parameters): # Thresholds are weekly, so multiply by weeks in year and divide by months in year primary_threshold = ( - parameters.thresholds.primary_threshold - * WEEKS_IN_YEAR - / MONTHS_IN_YEAR + parameters.thresholds.primary_threshold * WEEKS_IN_YEAR / MONTHS_IN_YEAR ) upper_earnings_limit = ( - parameters.thresholds.upper_earnings_limit - * WEEKS_IN_YEAR - / MONTHS_IN_YEAR + parameters.thresholds.upper_earnings_limit * WEEKS_IN_YEAR / MONTHS_IN_YEAR ) upper_earnings_limit_income = max_(income - upper_earnings_limit, 0) diff --git a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employer.py b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employer.py index 0e74bc5dd..d4f11fc59 100644 --- a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employer.py +++ b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_class_1_employer.py @@ -22,9 +22,7 @@ def formula(person, period, parameters): taxed_earnings = earnings + added_pension_contributions else: taxed_earnings = earnings - secondary_threshold = ( - class_1.thresholds.secondary_threshold * WEEKS_IN_YEAR - ) + secondary_threshold = class_1.thresholds.secondary_threshold * WEEKS_IN_YEAR main_earnings = max_( taxed_earnings - secondary_threshold, 0, diff --git a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_liable.py b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_liable.py index 656ba8ca1..cdea63ac9 100644 --- a/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_liable.py +++ b/policyengine_uk/variables/gov/hmrc/national_insurance/class_1/ni_liable.py @@ -3,9 +3,7 @@ class ni_liable(Variable): label = "NI liable" - documentation = ( - "Whether this person is liable for NI contributions by their age." - ) + documentation = "Whether this person is liable for NI contributions by their age." entity = Person definition_period = YEAR value_type = bool diff --git a/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py b/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py index 426126a99..bfe1f4b5d 100644 --- a/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py +++ b/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py @@ -19,9 +19,7 @@ def formula(person, period, parameters): step_2 = step_1 * main_rate step_3 = step_2 + 53 * ni.class_2.flat_rate class_2_contributions = person("ni_class_2", period) - primary_class_1_contributions = person( - "ni_class_1_employee_primary", period - ) + primary_class_1_contributions = person("ni_class_1_employee_primary", period) step_4 = step_3 - class_2_contributions - primary_class_1_contributions class_4_main_contributions = person("ni_class_4_main", period) other_aggregate_contributions = ( diff --git a/policyengine_uk/variables/gov/hmrc/national_insurance/salary_sacrifice_pension_ni_employee.py b/policyengine_uk/variables/gov/hmrc/national_insurance/salary_sacrifice_pension_ni_employee.py index 563009178..ba71d8579 100644 --- a/policyengine_uk/variables/gov/hmrc/national_insurance/salary_sacrifice_pension_ni_employee.py +++ b/policyengine_uk/variables/gov/hmrc/national_insurance/salary_sacrifice_pension_ni_employee.py @@ -23,9 +23,7 @@ def formula(person, period, parameters): # Use existing NI Class 1 parameters ni_params = parameters(period).gov.hmrc.national_insurance.class_1 employment_income = person("employment_income", period) - upper_earnings_limit = ( - ni_params.thresholds.upper_earnings_limit * WEEKS_IN_YEAR - ) + upper_earnings_limit = ni_params.thresholds.upper_earnings_limit * WEEKS_IN_YEAR # Apply appropriate NI rate based on income level # Main rate (8%) for income <= UEL, additional rate (2%) for income > UEL diff --git a/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_relief.py b/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_relief.py index 564f8d84a..a506e5872 100644 --- a/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_relief.py +++ b/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_relief.py @@ -18,9 +18,7 @@ def formula(person, period, parameters): age_limit = parameters( period ).gov.hmrc.pensions.pension_contributions_relief_age_limit - income = add( - person, period, ["employment_income", "self_employment_income"] - ) + income = add(person, period, ["employment_income", "self_employment_income"]) under_age_limit = person("age", period) < age_limit basic_amount = parameters( period diff --git a/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_via_salary_sacrifice_adjusted.py b/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_via_salary_sacrifice_adjusted.py index 1a35f459d..ec101cce4 100644 --- a/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_via_salary_sacrifice_adjusted.py +++ b/policyengine_uk/variables/gov/hmrc/pensions/pension_contributions_via_salary_sacrifice_adjusted.py @@ -15,9 +15,7 @@ class pension_contributions_via_salary_sacrifice_adjusted(Variable): reference = "https://policyengine.org/uk/research/salary-sacrifice-cap" def formula(person, period, parameters): - intended_ss = person( - "pension_contributions_via_salary_sacrifice", period - ) + intended_ss = person("pension_contributions_via_salary_sacrifice", period) cap = parameters( period ).gov.hmrc.national_insurance.salary_sacrifice_pension_cap diff --git a/policyengine_uk/variables/gov/hmrc/pensions/salary_sacrifice_returned_to_income.py b/policyengine_uk/variables/gov/hmrc/pensions/salary_sacrifice_returned_to_income.py index e316979b9..82bca2785 100644 --- a/policyengine_uk/variables/gov/hmrc/pensions/salary_sacrifice_returned_to_income.py +++ b/policyengine_uk/variables/gov/hmrc/pensions/salary_sacrifice_returned_to_income.py @@ -20,9 +20,7 @@ class salary_sacrifice_returned_to_income(Variable): reference = "https://policyengine.org/uk/research/uk-salary-sacrifice-cap" def formula(person, period, parameters): - intended_ss = person( - "pension_contributions_via_salary_sacrifice", period - ) + intended_ss = person("pension_contributions_via_salary_sacrifice", period) cap = parameters( period ).gov.hmrc.national_insurance.salary_sacrifice_pension_cap diff --git a/policyengine_uk/variables/gov/hmrc/sdlt_on_residential_property_transactions.py b/policyengine_uk/variables/gov/hmrc/sdlt_on_residential_property_transactions.py index 8ebe7f560..8d12e06ad 100644 --- a/policyengine_uk/variables/gov/hmrc/sdlt_on_residential_property_transactions.py +++ b/policyengine_uk/variables/gov/hmrc/sdlt_on_residential_property_transactions.py @@ -35,6 +35,4 @@ def formula(household, period, parameters): additional_residential_purchase_tax = ( stamp_duty.residential.purchase.additional.rate.calc(price) ) - return ( - main_residential_purchase_tax + additional_residential_purchase_tax - ) + return main_residential_purchase_tax + additional_residential_purchase_tax diff --git a/policyengine_uk/variables/gov/hmrc/student_loans/plan_1_interest_rate.py b/policyengine_uk/variables/gov/hmrc/student_loans/plan_1_interest_rate.py index df2762154..a3204aae6 100644 --- a/policyengine_uk/variables/gov/hmrc/student_loans/plan_1_interest_rate.py +++ b/policyengine_uk/variables/gov/hmrc/student_loans/plan_1_interest_rate.py @@ -18,6 +18,5 @@ def formula(person, period, parameters): p = parameters(period).gov return min_( p.economic_assumptions.yoy_growth.obr.rpi, - p.boe.base_rate - + p.hmrc.student_loans.interest_rates.plan_1.boe_margin, + p.boe.base_rate + p.hmrc.student_loans.interest_rates.plan_1.boe_margin, ) diff --git a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_meets_income_requirements.py b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_meets_income_requirements.py index a0da2161e..c40d8362d 100644 --- a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_meets_income_requirements.py +++ b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_meets_income_requirements.py @@ -14,9 +14,7 @@ def formula(person, period, parameters): p = parameters(period).gov.hmrc.tax_free_childcare # Calculate eligible income by summing countable sources - yearly_eligible_income = add( - person, period, p.income.countable_sources - ) + yearly_eligible_income = add(person, period, p.income.countable_sources) quarterly_income = yearly_eligible_income / 4 # Get minimum wage rate using existing variable @@ -29,6 +27,4 @@ def formula(person, period, parameters): # Get adjusted net income and check against max threshold ani = person("adjusted_net_income", period) - return (quarterly_income > required_threshold) & ( - ani < p.income.income_limit - ) + return (quarterly_income > required_threshold) & (ani < p.income.income_limit) diff --git a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_work_condition.py b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_work_condition.py index bc5a31c79..c61ed1d0b 100644 --- a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_work_condition.py +++ b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/tax_free_childcare_work_condition.py @@ -22,16 +22,13 @@ def formula(person, period, parameters): add( person, period, - p_gc_disability.eligibility - + p_gc_disability.severe.eligibility, + p_gc_disability.eligibility + p_gc_disability.severe.eligibility, ) > 0 ) has_incapacity = person("incapacity_benefit", period) > 0 - eligible_based_on_disability = ( - receives_disability_programs | has_incapacity - ) + eligible_based_on_disability = receives_disability_programs | has_incapacity # Build conditions # Single adult conditions @@ -40,9 +37,7 @@ def formula(person, period, parameters): # Couple conditions is_couple = person.benunit("is_couple", period) - benunit_has_condition = benunit.any( - eligible_based_on_disability & is_adult - ) + benunit_has_condition = benunit.any(eligible_based_on_disability & is_adult) benunit_has_worker = benunit.any(in_work & is_adult) couple_both_working = is_couple & benunit.all( in_work | ~person("is_parent", period) @@ -51,8 +46,4 @@ def formula(person, period, parameters): is_couple & benunit_has_worker & benunit_has_condition ) - return ( - single_working - | couple_both_working - | couple_one_working_one_disabled - ) + return single_working | couple_both_working | couple_one_working_one_disabled diff --git a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/is_child_receiving_tax_free_childcare.py b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/is_child_receiving_tax_free_childcare.py index 96c245e14..1e1ca4c07 100644 --- a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/is_child_receiving_tax_free_childcare.py +++ b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/is_child_receiving_tax_free_childcare.py @@ -4,16 +4,12 @@ class is_child_receiving_tax_free_childcare(Variable): value_type = bool entity = Person - label = ( - "child is eligible for tax-free childcare based on age and entitlement" - ) + label = "child is eligible for tax-free childcare based on age and entitlement" definition_period = YEAR def formula(person, period, parameters): # Check if child meets the age condition - meets_age_condition = person( - "tax_free_childcare_child_age_eligible", period - ) + meets_age_condition = person("tax_free_childcare_child_age_eligible", period) # Check if tax-free childcare contribution is greater than 0 tfc_amount = person("tax_free_childcare", period) diff --git a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare.py b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare.py index 277865f4a..4856717ab 100644 --- a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare.py +++ b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare.py @@ -30,9 +30,7 @@ def formula(person, period, parameters): # Cap the contribution at the maximum amounts max_amount = ( - where( - qualifies_for_higher_amount, p.disabled_child, p.standard_child - ) + where(qualifies_for_higher_amount, p.disabled_child, p.standard_child) * ~is_parent ) diff --git a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare_eligibility.py b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare_eligibility.py index 92686b15b..71d32a8d7 100644 --- a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare_eligibility.py +++ b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare_eligibility.py @@ -14,15 +14,11 @@ def formula(benunit, period, parameters): ) meets_income_condition = benunit.all( - benunit.members( - "tax_free_childcare_meets_income_requirements", period - ) + benunit.members("tax_free_childcare_meets_income_requirements", period) | ~benunit.members("is_parent", period) ) - childcare_eligible = benunit( - "tax_free_childcare_program_eligible", period - ) + childcare_eligible = benunit("tax_free_childcare_program_eligible", period) work_eligible = benunit("tax_free_childcare_work_condition", period) diff --git a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/would_claim_tfc.py b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/would_claim_tfc.py index 2a623372c..77755a1af 100644 --- a/policyengine_uk/variables/gov/hmrc/tax_free_childcare/would_claim_tfc.py +++ b/policyengine_uk/variables/gov/hmrc/tax_free_childcare/would_claim_tfc.py @@ -5,8 +5,6 @@ class would_claim_tfc(Variable): value_type = bool entity = BenUnit label = "would claim Tax-Free Childcare" - documentation = ( - "Whether this family would claim Tax-Free Childcare if eligible" - ) + documentation = "Whether this family would claim Tax-Free Childcare if eligible" definition_period = YEAR default_value = True diff --git a/policyengine_uk/variables/gov/hmrc/vat.py b/policyengine_uk/variables/gov/hmrc/vat.py index 2fa71e09a..e8ec1a589 100644 --- a/policyengine_uk/variables/gov/hmrc/vat.py +++ b/policyengine_uk/variables/gov/hmrc/vat.py @@ -10,9 +10,7 @@ class vat(Variable): def formula(household, period, parameters): full_rate_consumption = household("full_rate_vat_consumption", period) - reduced_rate_consumption = household( - "reduced_rate_vat_consumption", period - ) + reduced_rate_consumption = household("reduced_rate_vat_consumption", period) p = parameters(period).gov raw_vat = ( full_rate_consumption * p.hmrc.vat.standard_rate diff --git a/policyengine_uk/variables/gov/revenue_scotland/expected_lbtt.py b/policyengine_uk/variables/gov/revenue_scotland/expected_lbtt.py index 91d55ec85..755b72c1d 100644 --- a/policyengine_uk/variables/gov/revenue_scotland/expected_lbtt.py +++ b/policyengine_uk/variables/gov/revenue_scotland/expected_lbtt.py @@ -10,8 +10,6 @@ class expected_lbtt(Variable): unit = GBP def formula(household, period, parameters): - property_sale_rate = parameters( - period - ).gov.hmrc.stamp_duty.property_sale_rate + property_sale_rate = parameters(period).gov.hmrc.stamp_duty.property_sale_rate lbtt = household("land_and_buildings_transaction_tax", period) return property_sale_rate * lbtt diff --git a/policyengine_uk/variables/gov/revenue_scotland/lbtt_liable.py b/policyengine_uk/variables/gov/revenue_scotland/lbtt_liable.py index 7db980ae9..a9c1487c6 100644 --- a/policyengine_uk/variables/gov/revenue_scotland/lbtt_liable.py +++ b/policyengine_uk/variables/gov/revenue_scotland/lbtt_liable.py @@ -3,7 +3,9 @@ class lbtt_liable(Variable): label = "Liable for Land and Buildings Transaction Tax" - documentation = "Whether the household is liable for Land and Buildings Transaction Tax" + documentation = ( + "Whether the household is liable for Land and Buildings Transaction Tax" + ) entity = Household definition_period = YEAR value_type = bool diff --git a/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_non_residential_property_rent.py b/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_non_residential_property_rent.py index 985ceeaa7..61e9bbb63 100644 --- a/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_non_residential_property_rent.py +++ b/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_non_residential_property_rent.py @@ -3,9 +3,7 @@ class lbtt_on_non_residential_property_rent(Variable): label = "LBTT on non-residential property" - documentation = ( - "LBTT charge from purchase or rental of non-residential property" - ) + documentation = "LBTT charge from purchase or rental of non-residential property" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_rent.py b/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_rent.py index 94a6c58dc..b2d38c735 100644 --- a/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_rent.py +++ b/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_rent.py @@ -3,9 +3,7 @@ class lbtt_on_rent(Variable): label = "LBTT on property rental" - documentation = ( - "Land and Buildings Transaction Tax on property rental agreements" - ) + documentation = "Land and Buildings Transaction Tax on property rental agreements" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_residential_property_transactions.py b/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_residential_property_transactions.py index 2948eb9d3..b487383c8 100644 --- a/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_residential_property_transactions.py +++ b/policyengine_uk/variables/gov/revenue_scotland/lbtt_on_residential_property_transactions.py @@ -26,10 +26,6 @@ def formula(household, period, parameters): "additional_residential_property_purchased", period ) lbtt2 = lbtt.residential.rate.calc(second_home_price) - surcharge = ( - lbtt.residential.additional_residence_surcharge * second_home_price - ) + surcharge = lbtt.residential.additional_residence_surcharge * second_home_price additional_residential_purchase_tax = lbtt2 + surcharge - return ( - main_residential_purchase_tax + additional_residential_purchase_tax - ) + return main_residential_purchase_tax + additional_residential_purchase_tax diff --git a/policyengine_uk/variables/gov/simulation/labor_supply_response/relative_income_change.py b/policyengine_uk/variables/gov/simulation/labor_supply_response/relative_income_change.py index 42eb4a66e..6c6b6c33e 100644 --- a/policyengine_uk/variables/gov/simulation/labor_supply_response/relative_income_change.py +++ b/policyengine_uk/variables/gov/simulation/labor_supply_response/relative_income_change.py @@ -22,21 +22,13 @@ def formula(person, period, parameters): ) measurement_person = measurement_branch.populations["person"] baseline_person = baseline_branch.populations["person"] - baseline_net_income = baseline_person.household( - "household_net_income", period - ) - net_income = measurement_person.household( - "household_net_income", period - ) + baseline_net_income = baseline_person.household("household_net_income", period) + net_income = measurement_person.household("household_net_income", period) income_change_bound = parameters( period ).gov.simulation.labor_supply_responses.bounds.income_change # _c suffix for "clipped" baseline_net_income_c = np.clip(baseline_net_income, 1, None) net_income_c = np.clip(net_income, 1, None) - relative_change = ( - net_income_c - baseline_net_income_c - ) / baseline_net_income_c - return np.clip( - relative_change, -income_change_bound, income_change_bound - ) + relative_change = (net_income_c - baseline_net_income_c) / baseline_net_income_c + return np.clip(relative_change, -income_change_bound, income_change_bound) diff --git a/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible.py b/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible.py index 562c13736..4cb03989f 100644 --- a/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible.py +++ b/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible.py @@ -14,14 +14,10 @@ class is_scp_eligible(Variable): def formula(person, period, parameters): # Check if household is in Scotland - in_scotland = ( - person.household("country", period).decode_to_str() == "SCOTLAND" - ) + in_scotland = person.household("country", period).decode_to_str() == "SCOTLAND" # Get SCP parameters - p = parameters( - period - ).gov.social_security_scotland.scottish_child_payment + p = parameters(period).gov.social_security_scotland.scottish_child_payment weekly_amount = p.amount # SCP only available when amount > 0 (i.e., after Feb 2021) @@ -34,24 +30,16 @@ def formula(person, period, parameters): qb = p.qualifying_benefits benunit = person.benunit - receives_uc = ( - benunit("universal_credit", period) > 0 - ) & qb.universal_credit - receives_ctc = ( - benunit("child_tax_credit", period) > 0 - ) & qb.child_tax_credit + receives_uc = (benunit("universal_credit", period) > 0) & qb.universal_credit + receives_ctc = (benunit("child_tax_credit", period) > 0) & qb.child_tax_credit receives_wtc = ( benunit("working_tax_credit", period) > 0 ) & qb.working_tax_credit receives_income_support = ( benunit("income_support", period) > 0 ) & qb.income_support - receives_jsa_income = ( - benunit("jsa_income", period) > 0 - ) & qb.jsa_income - receives_esa_income = ( - benunit("esa_income", period) > 0 - ) & qb.esa_income + receives_jsa_income = (benunit("jsa_income", period) > 0) & qb.jsa_income + receives_esa_income = (benunit("esa_income", period) > 0) & qb.esa_income receives_pension_credit = ( benunit("pension_credit", period) > 0 ) & qb.pension_credit diff --git a/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible_child.py b/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible_child.py index 7ef246b55..ee0a3687f 100644 --- a/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible_child.py +++ b/policyengine_uk/variables/gov/social_security_scotland/is_scp_eligible_child.py @@ -3,15 +3,15 @@ class is_scp_eligible_child(Variable): label = "Eligible for Scottish Child Payment" - documentation = "Whether this child is eligible for Scottish Child Payment based on age." + documentation = ( + "Whether this child is eligible for Scottish Child Payment based on age." + ) entity = Person definition_period = YEAR value_type = bool def formula(person, period, parameters): - p = parameters( - period - ).gov.social_security_scotland.scottish_child_payment + p = parameters(period).gov.social_security_scotland.scottish_child_payment age = person("age", period) max_age = p.max_age return age < max_age diff --git a/policyengine_uk/variables/gov/social_security_scotland/pawhp.py b/policyengine_uk/variables/gov/social_security_scotland/pawhp.py index bfb34aae8..8cdbc70fb 100644 --- a/policyengine_uk/variables/gov/social_security_scotland/pawhp.py +++ b/policyengine_uk/variables/gov/social_security_scotland/pawhp.py @@ -9,9 +9,7 @@ class pawhp(Variable): unit = GBP def formula(household, period, parameters): - in_scotland = ( - household("country", period).decode_to_str() == "SCOTLAND" - ) + in_scotland = household("country", period).decode_to_str() == "SCOTLAND" age = household.members("age", period) is_SP_age = household.members("is_SP_age", period) wfp = parameters(period).gov.social_security_scotland.pawhp @@ -30,16 +28,13 @@ def formula(household, period, parameters): ) meets_mtb_requirement = on_mtb | ~wfp.eligibility.require_benefits meets_spa_requirement = ( - household.any(is_SP_age) - | ~wfp.eligibility.state_pension_age_requirement + household.any(is_SP_age) | ~wfp.eligibility.state_pension_age_requirement ) meets_higher_age_requirement = household.any( age >= wfp.eligibility.higher_age_requirement ) qualifies_for_higher = ( - meets_mtb_requirement - & meets_spa_requirement - & meets_higher_age_requirement + meets_mtb_requirement & meets_spa_requirement & meets_higher_age_requirement ) qualifies_for_lower = ( meets_mtb_requirement diff --git a/policyengine_uk/variables/gov/social_security_scotland/scottish_child_payment.py b/policyengine_uk/variables/gov/social_security_scotland/scottish_child_payment.py index c486ca540..05f1d09ae 100644 --- a/policyengine_uk/variables/gov/social_security_scotland/scottish_child_payment.py +++ b/policyengine_uk/variables/gov/social_security_scotland/scottish_child_payment.py @@ -19,9 +19,7 @@ class scottish_child_payment(Variable): def formula(person, period, parameters): # Get SCP parameters - p = parameters( - period - ).gov.social_security_scotland.scottish_child_payment + p = parameters(period).gov.social_security_scotland.scottish_child_payment weekly_amount = p.amount # Child-level take-up (generated stochastically in dataset) diff --git a/policyengine_uk/variables/gov/social_security_scotland/two_child_limit_payment.py b/policyengine_uk/variables/gov/social_security_scotland/two_child_limit_payment.py index 56bc311b1..6488d995c 100644 --- a/policyengine_uk/variables/gov/social_security_scotland/two_child_limit_payment.py +++ b/policyengine_uk/variables/gov/social_security_scotland/two_child_limit_payment.py @@ -17,9 +17,7 @@ class two_child_limit_payment(Variable): ] def formula(benunit, period, parameters): - in_scotland = ( - benunit.household("country", period).decode_to_str() == "SCOTLAND" - ) + in_scotland = benunit.household("country", period).decode_to_str() == "SCOTLAND" # Check if payment is in effect (from December 2024) in_effect = parameters( @@ -32,9 +30,7 @@ def formula(benunit, period, parameters): ).gov.dwp.universal_credit.elements.child.amount # Count children affected by the two-child limit - is_child_limit_affected = benunit.members( - "uc_is_child_limit_affected", period - ) + is_child_limit_affected = benunit.members("uc_is_child_limit_affected", period) affected_children = benunit.sum(is_child_limit_affected) # Payment equals the UC child element for each affected child diff --git a/policyengine_uk/variables/gov/treasury/cost_of_living_support/cost_of_living_support_payment.py b/policyengine_uk/variables/gov/treasury/cost_of_living_support/cost_of_living_support_payment.py index fd99f0365..7a6d9bc08 100644 --- a/policyengine_uk/variables/gov/treasury/cost_of_living_support/cost_of_living_support_payment.py +++ b/policyengine_uk/variables/gov/treasury/cost_of_living_support/cost_of_living_support_payment.py @@ -18,9 +18,7 @@ def formula(household, period, parameters): ) > 0 ) - means_test_bonus = ( - col.means_tested_households.amount * on_means_tested_benefits - ) + means_test_bonus = col.means_tested_households.amount * on_means_tested_benefits on_pensioner_benefits = ( add(household, period, col.pensioners.qualifying_benefits) > 0 diff --git a/policyengine_uk/variables/gov/treasury/energy_bills_rebate/council_tax_rebate.py b/policyengine_uk/variables/gov/treasury/energy_bills_rebate/council_tax_rebate.py index f80c4c1c3..d9b186149 100644 --- a/policyengine_uk/variables/gov/treasury/energy_bills_rebate/council_tax_rebate.py +++ b/policyengine_uk/variables/gov/treasury/energy_bills_rebate/council_tax_rebate.py @@ -10,18 +10,11 @@ class ebr_council_tax_rebate(Variable): unit = GBP def formula(household, period, parameters): - ctr = parameters( - period - ).gov.treasury.energy_bills_rebate.council_tax_rebate + ctr = parameters(period).gov.treasury.energy_bills_rebate.council_tax_rebate ct_band = household("council_tax_band", period) ct_band_values = ct_band.possible_values eligible = np.any( - np.array( - [ - ct_band == getattr(ct_band_values, band) - for band in ctr.bands - ] - ), + np.array([ct_band == getattr(ct_band_values, band) for band in ctr.bands]), axis=0, ) return eligible * ctr.amount diff --git a/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_consumption_level.py b/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_consumption_level.py index e196a1536..a0ceecaab 100644 --- a/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_consumption_level.py +++ b/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_consumption_level.py @@ -9,9 +9,7 @@ class monthly_epg_consumption_level(Variable): unit = "currency-GBP" def formula(household, period, parameters): - energy_consumption = household( - "monthly_domestic_energy_consumption", period - ) + energy_consumption = household("monthly_domestic_energy_consumption", period) ofgem = parameters.gov.ofgem price_cap = ofgem.energy_price_cap(period) price_guarantee = ofgem.energy_price_guarantee(period) diff --git a/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_subsidy.py b/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_subsidy.py index 88f99855c..24c7bbbf4 100644 --- a/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_subsidy.py +++ b/policyengine_uk/variables/gov/treasury/price_cap_subsidy/monthly_epg_subsidy.py @@ -9,10 +9,6 @@ class monthly_epg_subsidy(Variable): unit = "currency-GBP" def formula(household, period, parameters): - energy_consumption = household( - "monthly_domestic_energy_consumption", period - ) - epg_consumption_level = household( - "monthly_epg_consumption_level", period - ) + energy_consumption = household("monthly_domestic_energy_consumption", period) + epg_consumption_level = household("monthly_epg_consumption_level", period) return max_(0, energy_consumption - epg_consumption_level) diff --git a/policyengine_uk/variables/gov/wra/expected_ltt.py b/policyengine_uk/variables/gov/wra/expected_ltt.py index ddf0c6baf..7714d493d 100644 --- a/policyengine_uk/variables/gov/wra/expected_ltt.py +++ b/policyengine_uk/variables/gov/wra/expected_ltt.py @@ -10,8 +10,6 @@ class expected_ltt(Variable): unit = GBP def formula(household, period, parameters): - property_sale_rate = parameters( - period - ).gov.hmrc.stamp_duty.property_sale_rate + property_sale_rate = parameters(period).gov.hmrc.stamp_duty.property_sale_rate land_transaction_tax = household("land_transaction_tax", period) return property_sale_rate * land_transaction_tax diff --git a/policyengine_uk/variables/gov/wra/land_transaction_tax.py b/policyengine_uk/variables/gov/wra/land_transaction_tax.py index fbef94f7b..afb50f6ff 100644 --- a/policyengine_uk/variables/gov/wra/land_transaction_tax.py +++ b/policyengine_uk/variables/gov/wra/land_transaction_tax.py @@ -10,7 +10,5 @@ class land_transaction_tax(Variable): unit = GBP def formula(household, period): - ltt_if_liable = add( - household, period, ["ltt_on_transactions", "ltt_on_rent"] - ) + ltt_if_liable = add(household, period, ["ltt_on_transactions", "ltt_on_rent"]) return household("ltt_liable", period) * ltt_if_liable diff --git a/policyengine_uk/variables/gov/wra/ltt_on_non_residential_property_rent.py b/policyengine_uk/variables/gov/wra/ltt_on_non_residential_property_rent.py index 0ca0c0e16..64a572e92 100644 --- a/policyengine_uk/variables/gov/wra/ltt_on_non_residential_property_rent.py +++ b/policyengine_uk/variables/gov/wra/ltt_on_non_residential_property_rent.py @@ -3,7 +3,9 @@ class ltt_on_non_residential_property_rent(Variable): label = "LTT on non-residential property rent" - documentation = "Land Transaction Tax charge on non-residential property rental agreements" + documentation = ( + "Land Transaction Tax charge on non-residential property rental agreements" + ) entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/gov/wra/ltt_on_residential_property_transactions.py b/policyengine_uk/variables/gov/wra/ltt_on_residential_property_transactions.py index a4bd16bff..3eb8108c6 100644 --- a/policyengine_uk/variables/gov/wra/ltt_on_residential_property_transactions.py +++ b/policyengine_uk/variables/gov/wra/ltt_on_residential_property_transactions.py @@ -3,9 +3,7 @@ class ltt_on_residential_property_transactions(Variable): label = "LTT on residential property" - documentation = ( - "Land Transaction Tax charge on residential property transactions" - ) + documentation = "Land Transaction Tax charge on residential property transactions" entity = Household definition_period = YEAR value_type = float @@ -13,19 +11,12 @@ class ltt_on_residential_property_transactions(Variable): def formula(household, period, parameters): ltt = parameters(period).gov.wra.land_transaction_tax - main_home_price = household( - "main_residential_property_purchased", period - ) - primary_residential_purchase_tax = ltt.residential.primary.calc( - main_home_price - ) + main_home_price = household("main_residential_property_purchased", period) + primary_residential_purchase_tax = ltt.residential.primary.calc(main_home_price) second_home_price = household( "additional_residential_property_purchased", period ) additional_residential_purchase_tax = ltt.residential.higher_rate.calc( second_home_price ) - return ( - primary_residential_purchase_tax - + additional_residential_purchase_tax - ) + return primary_residential_purchase_tax + additional_residential_purchase_tax diff --git a/policyengine_uk/variables/household/cliff_evaluated.py b/policyengine_uk/variables/household/cliff_evaluated.py index e89385f5a..b5b367ed4 100644 --- a/policyengine_uk/variables/household/cliff_evaluated.py +++ b/policyengine_uk/variables/household/cliff_evaluated.py @@ -11,7 +11,5 @@ class cliff_evaluated(Variable): def formula(person, period, parameters): adult_index_values = person("adult_index", period) - cliff_adult_count = parameters( - period - ).gov.simulation.marginal_tax_rate_adults + cliff_adult_count = parameters(period).gov.simulation.marginal_tax_rate_adults return adult_index_values <= cliff_adult_count diff --git a/policyengine_uk/variables/household/consumption/benunit_rent.py b/policyengine_uk/variables/household/consumption/benunit_rent.py index dbcb6528d..e5833afc8 100644 --- a/policyengine_uk/variables/household/consumption/benunit_rent.py +++ b/policyengine_uk/variables/household/consumption/benunit_rent.py @@ -5,7 +5,9 @@ class benunit_rent(Variable): value_type = float entity = BenUnit label = "Rent" - documentation = "Gross rent that members of this family are liable for (social housing only)" + documentation = ( + "Gross rent that members of this family are liable for (social housing only)" + ) definition_period = YEAR unit = GBP uprating = "gov.economic_assumptions.indices.obr.social_rent" diff --git a/policyengine_uk/variables/household/consumption/diesel_litres.py b/policyengine_uk/variables/household/consumption/diesel_litres.py index 54c150178..f4b0efefc 100644 --- a/policyengine_uk/variables/household/consumption/diesel_litres.py +++ b/policyengine_uk/variables/household/consumption/diesel_litres.py @@ -10,6 +10,4 @@ class diesel_litres(Variable): unit = GBP def formula(household, period, parameters): - return household("diesel_spending", period) / household( - "diesel_price", period - ) + return household("diesel_spending", period) / household("diesel_price", period) diff --git a/policyengine_uk/variables/household/consumption/petrol_litres.py b/policyengine_uk/variables/household/consumption/petrol_litres.py index c24caf325..2effd42d3 100644 --- a/policyengine_uk/variables/household/consumption/petrol_litres.py +++ b/policyengine_uk/variables/household/consumption/petrol_litres.py @@ -10,6 +10,4 @@ class petrol_litres(Variable): unit = GBP def formula(household, period, parameters): - return household("petrol_spending", period) / household( - "petrol_price", period - ) + return household("petrol_spending", period) / household("petrol_price", period) diff --git a/policyengine_uk/variables/household/demographic/carer_premium.py b/policyengine_uk/variables/household/demographic/carer_premium.py index 81191362b..fd151e5ae 100644 --- a/policyengine_uk/variables/household/demographic/carer_premium.py +++ b/policyengine_uk/variables/household/demographic/carer_premium.py @@ -6,9 +6,7 @@ class carer_premium(Variable): entity = BenUnit label = "Carer premium" definition_period = YEAR - reference = ( - "The Social Security Amendment (Carer Premium) Regulations 2002" - ) + reference = "The Social Security Amendment (Carer Premium) Regulations 2002" unit = GBP def formula(benunit, period, parameters): diff --git a/policyengine_uk/variables/household/demographic/disability_premium.py b/policyengine_uk/variables/household/demographic/disability_premium.py index c819bf1ea..e26f49195 100644 --- a/policyengine_uk/variables/household/demographic/disability_premium.py +++ b/policyengine_uk/variables/household/demographic/disability_premium.py @@ -6,7 +6,9 @@ class disability_premium(Variable): entity = BenUnit label = "Disability premium" definition_period = YEAR - reference = "The Social Security Amendment (Enhanced Disability Premium) Regulations 2000" + reference = ( + "The Social Security Amendment (Enhanced Disability Premium) Regulations 2000" + ) unit = GBP def formula(benunit, period, parameters): @@ -15,8 +17,6 @@ def formula(benunit, period, parameters): couple = benunit("is_couple", period.this_year) single_premium = single * dis.disability_single couple_premium = couple * dis.disability_couple - has_disabled_adults = ( - benunit("num_disabled_adults", period.this_year) > 0 - ) + has_disabled_adults = benunit("num_disabled_adults", period.this_year) > 0 weekly_amount = single_premium + couple_premium return weekly_amount * WEEKS_IN_YEAR * has_disabled_adults diff --git a/policyengine_uk/variables/household/demographic/enhanced_disability_premium.py b/policyengine_uk/variables/household/demographic/enhanced_disability_premium.py index 184a75188..c2f8d7c4f 100644 --- a/policyengine_uk/variables/household/demographic/enhanced_disability_premium.py +++ b/policyengine_uk/variables/household/demographic/enhanced_disability_premium.py @@ -6,7 +6,9 @@ class enhanced_disability_premium(Variable): entity = BenUnit label = "Enhanced disability premium" definition_period = YEAR - reference = "The Social Security Amendment (Enhanced Disability Premium) Regulations 2000" + reference = ( + "The Social Security Amendment (Enhanced Disability Premium) Regulations 2000" + ) unit = GBP def formula(benunit, period, parameters): diff --git a/policyengine_uk/variables/household/demographic/is_blind.py b/policyengine_uk/variables/household/demographic/is_blind.py index a058651cd..1682ebecf 100644 --- a/policyengine_uk/variables/household/demographic/is_blind.py +++ b/policyengine_uk/variables/household/demographic/is_blind.py @@ -3,7 +3,9 @@ class is_blind(Variable): label = "Blind" - documentation = "Certified as blind or severely sight impaired by a consultant ophthalmologist" + documentation = ( + "Certified as blind or severely sight impaired by a consultant ophthalmologist" + ) entity = Person definition_period = YEAR value_type = bool diff --git a/policyengine_uk/variables/household/demographic/is_eldest_child.py b/policyengine_uk/variables/household/demographic/is_eldest_child.py index cce261193..91a13a0e0 100644 --- a/policyengine_uk/variables/household/demographic/is_eldest_child.py +++ b/policyengine_uk/variables/household/demographic/is_eldest_child.py @@ -4,9 +4,7 @@ class is_eldest_child(Variable): label = "Is the eldest child" - documentation = ( - "Whether this person is the eldest child in the benefit unit" - ) + documentation = "Whether this person is the eldest child in the benefit unit" entity = Person definition_period = YEAR value_type = bool diff --git a/policyengine_uk/variables/household/demographic/is_parent.py b/policyengine_uk/variables/household/demographic/is_parent.py index 540c8202d..6f5d7f892 100644 --- a/policyengine_uk/variables/household/demographic/is_parent.py +++ b/policyengine_uk/variables/household/demographic/is_parent.py @@ -20,13 +20,11 @@ def formula(person, period, parameters): family_types = family_type.possible_values # For lone parents (FamilyType.LONE_PARENT), only the eldest is parent - is_lone_parent = (family_type == family_types.LONE_PARENT) & ( - adult_index == 1 - ) + is_lone_parent = (family_type == family_types.LONE_PARENT) & (adult_index == 1) # For couples with children (FamilyType.COUPLE_WITH_CHILDREN), two eldest are parents - is_couple_parent = ( - family_type == family_types.COUPLE_WITH_CHILDREN - ) & ((adult_index == 1) | (adult_index == 2)) + is_couple_parent = (family_type == family_types.COUPLE_WITH_CHILDREN) & ( + (adult_index == 1) | (adult_index == 2) + ) return is_lone_parent | is_couple_parent diff --git a/policyengine_uk/variables/household/demographic/is_severely_disabled_for_benefits.py b/policyengine_uk/variables/household/demographic/is_severely_disabled_for_benefits.py index 16dc1b6aa..c648487f9 100644 --- a/policyengine_uk/variables/household/demographic/is_severely_disabled_for_benefits.py +++ b/policyengine_uk/variables/household/demographic/is_severely_disabled_for_benefits.py @@ -5,9 +5,7 @@ class is_severely_disabled_for_benefits(Variable): value_type = bool entity = Person label = "Has a severe disability" - documentation = ( - "Whether this person is severely disabled for benefits purposes" - ) + documentation = "Whether this person is severely disabled for benefits purposes" definition_period = YEAR reference = "Child Tax Credit Regulations 2002 s. 8" @@ -16,13 +14,11 @@ def formula(person, period, parameters): THRESHOLD_SAFETY_GAP = 10 * WEEKS_IN_YEAR paragraph_3 = ( person("dla_sc", period) - >= benefit.dla.self_care.higher * WEEKS_IN_YEAR - - THRESHOLD_SAFETY_GAP + >= benefit.dla.self_care.higher * WEEKS_IN_YEAR - THRESHOLD_SAFETY_GAP ) paragraph_4 = ( person("pip_dl", period) - >= benefit.pip.daily_living.enhanced * WEEKS_IN_YEAR - - THRESHOLD_SAFETY_GAP + >= benefit.pip.daily_living.enhanced * WEEKS_IN_YEAR - THRESHOLD_SAFETY_GAP ) paragraph_5 = person("afcs", period) > 0 return sum([paragraph_3, paragraph_4, paragraph_5]) > 0 diff --git a/policyengine_uk/variables/household/demographic/locations.py b/policyengine_uk/variables/household/demographic/locations.py index 70e5b64f6..0c67fb004 100644 --- a/policyengine_uk/variables/household/demographic/locations.py +++ b/policyengine_uk/variables/household/demographic/locations.py @@ -217,9 +217,7 @@ class LocalAuthority(Enum): ANTRIM_AND_NEWTOWNABBEY = "Antrim and Newtownabbey" ARDS_AND_NORTH_DOWN = "Ards and North Down" ARGYLL_AND_BUTE = "Argyll and Bute" - ARMAGH_CITY_BANBRIDGE_AND_CRAIGAVON = ( - "Armagh City, Banbridge and Craigavon" - ) + ARMAGH_CITY_BANBRIDGE_AND_CRAIGAVON = "Armagh City, Banbridge and Craigavon" ARUN = "Arun" ASHFIELD = "Ashfield" ASHFORD = "Ashford" diff --git a/policyengine_uk/variables/household/demographic/num_enhanced_disabled_adults.py b/policyengine_uk/variables/household/demographic/num_enhanced_disabled_adults.py index 8c4d77afb..8dc90fe17 100644 --- a/policyengine_uk/variables/household/demographic/num_enhanced_disabled_adults.py +++ b/policyengine_uk/variables/household/demographic/num_enhanced_disabled_adults.py @@ -9,7 +9,5 @@ class num_enhanced_disabled_adults(Variable): def formula(benunit, period, parameters): adult = benunit.members("is_adult", period) - enhanced_disabled = benunit.members( - "is_enhanced_disabled_for_benefits", period - ) + enhanced_disabled = benunit.members("is_enhanced_disabled_for_benefits", period) return benunit.sum(adult & enhanced_disabled) diff --git a/policyengine_uk/variables/household/demographic/num_enhanced_disabled_children.py b/policyengine_uk/variables/household/demographic/num_enhanced_disabled_children.py index 04bd60b77..10f5dd860 100644 --- a/policyengine_uk/variables/household/demographic/num_enhanced_disabled_children.py +++ b/policyengine_uk/variables/household/demographic/num_enhanced_disabled_children.py @@ -9,7 +9,5 @@ class num_enhanced_disabled_children(Variable): def formula(benunit, period, parameters): child = benunit.members("is_child_or_QYP", period) - enhanced_disabled = benunit.members( - "is_enhanced_disabled_for_benefits", period - ) + enhanced_disabled = benunit.members("is_enhanced_disabled_for_benefits", period) return benunit.sum(child & enhanced_disabled) diff --git a/policyengine_uk/variables/household/demographic/num_severely_disabled_adults.py b/policyengine_uk/variables/household/demographic/num_severely_disabled_adults.py index 7fd4c2289..fef66b4f0 100644 --- a/policyengine_uk/variables/household/demographic/num_severely_disabled_adults.py +++ b/policyengine_uk/variables/household/demographic/num_severely_disabled_adults.py @@ -9,7 +9,5 @@ class num_severely_disabled_adults(Variable): def formula(benunit, period, parameters): adult = benunit.members("is_adult", period) - severely_disabled = benunit.members( - "is_severely_disabled_for_benefits", period - ) + severely_disabled = benunit.members("is_severely_disabled_for_benefits", period) return benunit.sum(adult & severely_disabled) diff --git a/policyengine_uk/variables/household/demographic/num_severely_disabled_children.py b/policyengine_uk/variables/household/demographic/num_severely_disabled_children.py index 2b2c8d594..8bb07cd51 100644 --- a/policyengine_uk/variables/household/demographic/num_severely_disabled_children.py +++ b/policyengine_uk/variables/household/demographic/num_severely_disabled_children.py @@ -9,7 +9,5 @@ class num_severely_disabled_children(Variable): def formula(benunit, period, parameters): child = benunit.members("is_child_or_QYP", period) - severely_disabled = benunit.members( - "is_severely_disabled_for_benefits", period - ) + severely_disabled = benunit.members("is_severely_disabled_for_benefits", period) return benunit.sum(child & severely_disabled) diff --git a/policyengine_uk/variables/household/demographic/severe_disability_premium.py b/policyengine_uk/variables/household/demographic/severe_disability_premium.py index 727c57c76..c8501f4e1 100644 --- a/policyengine_uk/variables/household/demographic/severe_disability_premium.py +++ b/policyengine_uk/variables/household/demographic/severe_disability_premium.py @@ -6,7 +6,9 @@ class severe_disability_premium(Variable): entity = BenUnit label = "Severe disability premium" definition_period = YEAR - reference = "The Social Security Amendment (Enhanced Disability Premium) Regulations 2000" + reference = ( + "The Social Security Amendment (Enhanced Disability Premium) Regulations 2000" + ) unit = GBP def formula(benunit, period, parameters): diff --git a/policyengine_uk/variables/household/income/claims_all_entitled_benefits.py b/policyengine_uk/variables/household/income/claims_all_entitled_benefits.py index 9cc15032e..bb6643e7b 100644 --- a/policyengine_uk/variables/household/income/claims_all_entitled_benefits.py +++ b/policyengine_uk/variables/household/income/claims_all_entitled_benefits.py @@ -6,9 +6,7 @@ class claims_all_entitled_benefits(Variable): entity = BenUnit label = "Claims all eligible benefits" definition_period = YEAR - documentation = ( - "Whether this family would claim any benefit they are entitled to" - ) + documentation = "Whether this family would claim any benefit they are entitled to" def formula(benunit, period, parameters): # Return false if we have any reported values in the simulation for benefits. diff --git a/policyengine_uk/variables/household/income/hbai_excluded_income.py b/policyengine_uk/variables/household/income/hbai_excluded_income.py index 5fb23d87c..c76d27f3c 100644 --- a/policyengine_uk/variables/household/income/hbai_excluded_income.py +++ b/policyengine_uk/variables/household/income/hbai_excluded_income.py @@ -3,9 +3,7 @@ class hbai_excluded_income(Variable): label = "HBAI-excluded income" - documentation = ( - "Total value of income not included in HBAI household net income" - ) + documentation = "Total value of income not included in HBAI household net income" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/household/income/household_benefits.py b/policyengine_uk/variables/household/income/household_benefits.py index 9d82a3437..3821be75c 100644 --- a/policyengine_uk/variables/household/income/household_benefits.py +++ b/policyengine_uk/variables/household/income/household_benefits.py @@ -59,18 +59,12 @@ def formula(household, period, parameters): benefits = household_benefits.adds if contrib.abolish_council_tax: benefits = [ - benefit - for benefit in benefits - if benefit != "council_tax_benefit" + benefit for benefit in benefits if benefit != "council_tax_benefit" ] general_benefits = add( household, period, - [ - benefit - for benefit in benefits - if benefit not in ["basic_income"] - ], + [benefit for benefit in benefits if benefit not in ["basic_income"]], ) non_sp_benefits = add( household, diff --git a/policyengine_uk/variables/household/income/household_income_decile.py b/policyengine_uk/variables/household/income/household_income_decile.py index 785b1068a..e68d4c11e 100644 --- a/policyengine_uk/variables/household/income/household_income_decile.py +++ b/policyengine_uk/variables/household/income/household_income_decile.py @@ -14,9 +14,7 @@ def formula(household, period, parameters): income = household("equiv_hbai_household_net_income", period) count_people = household("household_count_people", period) household_weight = household("household_weight", period) - weighted_income = MicroSeries( - income, weights=household_weight * count_people - ) + weighted_income = MicroSeries(income, weights=household_weight * count_people) decile = weighted_income.decile_rank().values # Set negatives to -1. # This avoids the bottom decile summing to a negative number, diff --git a/policyengine_uk/variables/household/income/household_market_income.py b/policyengine_uk/variables/household/income/household_market_income.py index 9c5ad7a52..ec7578c93 100644 --- a/policyengine_uk/variables/household/income/household_market_income.py +++ b/policyengine_uk/variables/household/income/household_market_income.py @@ -25,7 +25,5 @@ class household_market_income(Variable): def formula(person, period, parameters): total = add(person, period, household_market_income.adds) - contrib = parameters( - period - ).gov.contrib.policyengine.economy.gdp_per_capita + contrib = parameters(period).gov.contrib.policyengine.economy.gdp_per_capita return total * (contrib + 1) diff --git a/policyengine_uk/variables/household/income/in_deep_poverty_ahc.py b/policyengine_uk/variables/household/income/in_deep_poverty_ahc.py index feb370179..0ec7831d6 100644 --- a/policyengine_uk/variables/household/income/in_deep_poverty_ahc.py +++ b/policyengine_uk/variables/household/income/in_deep_poverty_ahc.py @@ -9,7 +9,5 @@ class in_deep_poverty_ahc(Variable): def formula(household, period, parameters): income = household("equiv_hbai_household_net_income_ahc", period) - threshold = parameters( - period - ).household.poverty.absolute_poverty_threshold_ahc + threshold = parameters(period).household.poverty.absolute_poverty_threshold_ahc return income < (threshold * WEEKS_IN_YEAR / 2) diff --git a/policyengine_uk/variables/household/income/in_deep_poverty_bhc.py b/policyengine_uk/variables/household/income/in_deep_poverty_bhc.py index abab678f6..cfa11ac25 100644 --- a/policyengine_uk/variables/household/income/in_deep_poverty_bhc.py +++ b/policyengine_uk/variables/household/income/in_deep_poverty_bhc.py @@ -9,7 +9,5 @@ class in_deep_poverty_bhc(Variable): def formula(household, period, parameters): income = household("equiv_hbai_household_net_income", period) - threshold = parameters( - period - ).household.poverty.absolute_poverty_threshold_bhc + threshold = parameters(period).household.poverty.absolute_poverty_threshold_bhc return income < (threshold * WEEKS_IN_YEAR / 2) diff --git a/policyengine_uk/variables/household/income/in_poverty_ahc.py b/policyengine_uk/variables/household/income/in_poverty_ahc.py index ac71c6d7c..6406806af 100644 --- a/policyengine_uk/variables/household/income/in_poverty_ahc.py +++ b/policyengine_uk/variables/household/income/in_poverty_ahc.py @@ -9,7 +9,5 @@ class in_poverty_ahc(Variable): def formula(household, period, parameters): income = household("equiv_hbai_household_net_income_ahc", period) - threshold = parameters( - period - ).household.poverty.absolute_poverty_threshold_ahc + threshold = parameters(period).household.poverty.absolute_poverty_threshold_ahc return income < (threshold * WEEKS_IN_YEAR) diff --git a/policyengine_uk/variables/household/income/in_poverty_bhc.py b/policyengine_uk/variables/household/income/in_poverty_bhc.py index 68c9a4146..a3d506145 100644 --- a/policyengine_uk/variables/household/income/in_poverty_bhc.py +++ b/policyengine_uk/variables/household/income/in_poverty_bhc.py @@ -4,9 +4,7 @@ class in_poverty_bhc(Variable): value_type = bool entity = Household - label = ( - "Whether the household is in absolute poverty, before housing costs" - ) + label = "Whether the household is in absolute poverty, before housing costs" definition_period = YEAR def formula(household, period, parameters): diff --git a/policyengine_uk/variables/household/income/in_work.py b/policyengine_uk/variables/household/income/in_work.py index d6abb86bc..b88e65e8b 100644 --- a/policyengine_uk/variables/household/income/in_work.py +++ b/policyengine_uk/variables/household/income/in_work.py @@ -11,8 +11,6 @@ class in_work(Variable): def formula(person, period, parameters): has_hours_worked = person("hours_worked", period) > 0 - earnings = add( - person, period, ["employment_income", "self_employment_income"] - ) + earnings = add(person, period, ["employment_income", "self_employment_income"]) has_earnings = earnings > 0 return has_hours_worked | has_earnings diff --git a/policyengine_uk/variables/household/income/inflation_adjustment.py b/policyengine_uk/variables/household/income/inflation_adjustment.py index 0997946d9..996763f91 100644 --- a/policyengine_uk/variables/household/income/inflation_adjustment.py +++ b/policyengine_uk/variables/household/income/inflation_adjustment.py @@ -4,18 +4,14 @@ class inflation_adjustment(Variable): - label = ( - f"inflation multiplier to get {datetime.datetime.now().year} prices" - ) + label = f"inflation multiplier to get {datetime.datetime.now().year} prices" entity = Household definition_period = YEAR value_type = float unit = "/1" def formula(household, period, parameters): - cpi = ( - parameters.gov.economic_assumptions.indices.obr.consumer_price_index - ) + cpi = parameters.gov.economic_assumptions.indices.obr.consumer_price_index current_period_cpi = cpi(period) now_cpi = cpi(datetime.datetime.now().strftime("%Y-01-01")) return now_cpi / current_period_cpi @@ -29,9 +25,7 @@ class inflation_adjustment_ahc(Variable): unit = "/1" def formula(household, period, parameters): - cpi = ( - parameters.gov.economic_assumptions.indices.obr.consumer_price_index - ) + cpi = parameters.gov.economic_assumptions.indices.obr.consumer_price_index cpi_ahc = ( parameters.gov.economic_assumptions.indices.obr.consumer_price_index_ahc ) diff --git a/policyengine_uk/variables/household/income/is_QYP.py b/policyengine_uk/variables/household/income/is_QYP.py index 90cbe847b..afd72ce74 100644 --- a/policyengine_uk/variables/household/income/is_QYP.py +++ b/policyengine_uk/variables/household/income/is_QYP.py @@ -10,7 +10,5 @@ class is_QYP(Variable): def formula(person, period, parameters): education = person("current_education", period) under_20 = person("age", period) < 20 - in_education = ~( - education == education.possible_values.NOT_IN_EDUCATION - ) + in_education = ~(education == education.possible_values.NOT_IN_EDUCATION) return under_20 & in_education diff --git a/policyengine_uk/variables/household/income/is_child_or_QYP.py b/policyengine_uk/variables/household/income/is_child_or_QYP.py index ef43be15a..ea4d8ceb9 100644 --- a/policyengine_uk/variables/household/income/is_child_or_QYP.py +++ b/policyengine_uk/variables/household/income/is_child_or_QYP.py @@ -4,7 +4,9 @@ class is_child_or_QYP(Variable): value_type = bool entity = Person - label = "Whether this person is a child or qualifying young person for most benefits" + label = ( + "Whether this person is a child or qualifying young person for most benefits" + ) definition_period = YEAR def formula(person, period, parameters): diff --git a/policyengine_uk/variables/household/income/poverty_line_ahc.py b/policyengine_uk/variables/household/income/poverty_line_ahc.py index 0235d0d75..d39a2a4ba 100644 --- a/policyengine_uk/variables/household/income/poverty_line_ahc.py +++ b/policyengine_uk/variables/household/income/poverty_line_ahc.py @@ -8,8 +8,6 @@ class poverty_line_ahc(Variable): definition_period = YEAR def formula(household, period, parameters): - threshold = parameters( - period - ).household.poverty.absolute_poverty_threshold_ahc + threshold = parameters(period).household.poverty.absolute_poverty_threshold_ahc equivalisation = household("household_equivalisation_ahc", period) return threshold * equivalisation * WEEKS_IN_YEAR diff --git a/policyengine_uk/variables/household/income/poverty_line_bhc.py b/policyengine_uk/variables/household/income/poverty_line_bhc.py index b79bfb3bc..0973ed7d6 100644 --- a/policyengine_uk/variables/household/income/poverty_line_bhc.py +++ b/policyengine_uk/variables/household/income/poverty_line_bhc.py @@ -8,8 +8,6 @@ class poverty_line_bhc(Variable): definition_period = YEAR def formula(household, period, parameters): - threshold = parameters( - period - ).household.poverty.absolute_poverty_threshold_bhc + threshold = parameters(period).household.poverty.absolute_poverty_threshold_bhc equivalisation = household("household_equivalisation_bhc", period) return threshold * equivalisation * WEEKS_IN_YEAR diff --git a/policyengine_uk/variables/household/income/real_household_net_income.py b/policyengine_uk/variables/household/income/real_household_net_income.py index 16fe9a35d..d762af06d 100644 --- a/policyengine_uk/variables/household/income/real_household_net_income.py +++ b/policyengine_uk/variables/household/income/real_household_net_income.py @@ -4,9 +4,7 @@ class real_household_net_income(Variable): - label = ( - f"real household net income ({datetime.datetime.now().year} prices)" - ) + label = f"real household net income ({datetime.datetime.now().year} prices)" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/household/income/real_household_net_income_ahc.py b/policyengine_uk/variables/household/income/real_household_net_income_ahc.py index 2df75c855..5cdd1c50e 100644 --- a/policyengine_uk/variables/household/income/real_household_net_income_ahc.py +++ b/policyengine_uk/variables/household/income/real_household_net_income_ahc.py @@ -4,9 +4,7 @@ class real_household_net_income_ahc(Variable): - label = ( - f"real household net income ({datetime.datetime.now().year} prices)" - ) + label = f"real household net income ({datetime.datetime.now().year} prices)" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/household/marginal_tax_rate.py b/policyengine_uk/variables/household/marginal_tax_rate.py index 3e4d56253..6c0345d08 100644 --- a/policyengine_uk/variables/household/marginal_tax_rate.py +++ b/policyengine_uk/variables/household/marginal_tax_rate.py @@ -4,7 +4,9 @@ class marginal_tax_rate(Variable): label = "Marginal tax rate" - documentation = "Percent of marginal income gains that do not increase household net income." + documentation = ( + "Percent of marginal income gains that do not increase household net income." + ) entity = Person definition_period = YEAR value_type = float @@ -18,14 +20,10 @@ def formula(person, period, parameters): delta = p.marginal_tax_rate_delta adult_count = p.marginal_tax_rate_adults for adult_index in range(1, 1 + adult_count): - alt_simulation = simulation.get_branch( - f"adult_{adult_index}_pay_rise" - ) + alt_simulation = simulation.get_branch(f"adult_{adult_index}_pay_rise") mask = adult_index_values == adult_index for variable in simulation.tax_benefit_system.variables: - variable_data = simulation.tax_benefit_system.variables[ - variable - ] + variable_data = simulation.tax_benefit_system.variables[variable] if ( variable not in simulation.input_variables and not variable_data.is_input_variable() @@ -37,14 +35,10 @@ def formula(person, period, parameters): person("employment_income", period) + mask * delta, ) alt_person = alt_simulation.person - household_net_income = person.household( - "household_net_income", period - ) + household_net_income = person.household("household_net_income", period) household_net_income_higher_earnings = alt_person.household( "household_net_income", period ) - increase = ( - household_net_income_higher_earnings - household_net_income - ) + increase = household_net_income_higher_earnings - household_net_income mtr_values += where(mask, 1 - increase / delta, 0) return mtr_values diff --git a/policyengine_uk/variables/household/wealth/corporate_land_value.py b/policyengine_uk/variables/household/wealth/corporate_land_value.py index 3dfcd9cb3..59f0dd2c4 100644 --- a/policyengine_uk/variables/household/wealth/corporate_land_value.py +++ b/policyengine_uk/variables/household/wealth/corporate_land_value.py @@ -14,7 +14,6 @@ def formula(household, period, parameters): wealth = parameters(period).household.wealth corporate_wealth = household("corporate_wealth", period) corporate_wealth_intensity = ( - wealth.land.value.aggregate_corporate_land_value - / wealth.corporate_wealth + wealth.land.value.aggregate_corporate_land_value / wealth.corporate_wealth ) return corporate_wealth * corporate_wealth_intensity diff --git a/policyengine_uk/variables/household/wealth/household_land_value.py b/policyengine_uk/variables/household/wealth/household_land_value.py index b57874561..9d6cfca44 100644 --- a/policyengine_uk/variables/household/wealth/household_land_value.py +++ b/policyengine_uk/variables/household/wealth/household_land_value.py @@ -4,9 +4,7 @@ class household_land_value(Variable): entity = Household label = "Land value" - documentation = ( - "Estimated total land value directly owned by the household" - ) + documentation = "Estimated total land value directly owned by the household" unit = GBP definition_period = YEAR value_type = float @@ -15,8 +13,7 @@ class household_land_value(Variable): def formula(household, period, parameters): wealth = parameters(period).household.wealth property_wealth_intensity = ( - wealth.land.value.aggregate_household_land_value - / wealth.property_wealth + wealth.land.value.aggregate_household_land_value / wealth.property_wealth ) property_wealth = household("property_wealth", period) owned_land = household("owned_land", period) diff --git a/policyengine_uk/variables/household/wealth/household_wealth_decile.py b/policyengine_uk/variables/household/wealth/household_wealth_decile.py index efaa62dc2..adb7be72a 100644 --- a/policyengine_uk/variables/household/wealth/household_wealth_decile.py +++ b/policyengine_uk/variables/household/wealth/household_wealth_decile.py @@ -12,9 +12,7 @@ def formula(household, period, parameters): wealth = household("total_wealth", period) count_people = household("household_count_people", period) household_weight = household("household_weight", period) - weighted_wealth = MicroSeries( - wealth, weights=household_weight * count_people - ) + weighted_wealth = MicroSeries(wealth, weights=household_weight * count_people) decile = weighted_wealth.decile_rank().values # Set negatives to -1. # This avoids the bottom decile summing to a negative number, diff --git a/policyengine_uk/variables/household/wealth/land_value.py b/policyengine_uk/variables/household/wealth/land_value.py index 085eca259..21746b0ad 100644 --- a/policyengine_uk/variables/household/wealth/land_value.py +++ b/policyengine_uk/variables/household/wealth/land_value.py @@ -3,9 +3,7 @@ class land_value(Variable): label = "Land value" - documentation = ( - "Estimated total land value (directly and indirectly owned)" - ) + documentation = "Estimated total land value (directly and indirectly owned)" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/input/consumption/housing_water_and_electricity_consumption.py b/policyengine_uk/variables/input/consumption/housing_water_and_electricity_consumption.py index 9e242ba5f..13ae54c85 100644 --- a/policyengine_uk/variables/input/consumption/housing_water_and_electricity_consumption.py +++ b/policyengine_uk/variables/input/consumption/housing_water_and_electricity_consumption.py @@ -6,9 +6,7 @@ class housing_water_and_electricity_consumption(Variable): entity = Household label = "housing, water and electricity consumption" - documentation = ( - "Total yearly expenditure on housing, water and electricity" - ) + documentation = "Total yearly expenditure on housing, water and electricity" unit = GBP definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/input/dla_m_category.py b/policyengine_uk/variables/input/dla_m_category.py index 84b4b7737..1c695eeee 100644 --- a/policyengine_uk/variables/input/dla_m_category.py +++ b/policyengine_uk/variables/input/dla_m_category.py @@ -16,9 +16,7 @@ class dla_m_category(Variable): def formula(person, period, parameters): dla_m = parameters(period).baseline.gov.dwp.dla.mobility SAFETY_MARGIN = 0.1 # Survey reported values could be slightly below eligible values when they should be above due to data manipulation - reported_weekly_dla_m = ( - person("dla_m_reported", period) / WEEKS_IN_YEAR - ) + reported_weekly_dla_m = person("dla_m_reported", period) / WEEKS_IN_YEAR return select( [ reported_weekly_dla_m >= dla_m.higher * (1 - SAFETY_MARGIN), diff --git a/policyengine_uk/variables/input/dla_sc_category.py b/policyengine_uk/variables/input/dla_sc_category.py index 817d8f401..3a936cd85 100644 --- a/policyengine_uk/variables/input/dla_sc_category.py +++ b/policyengine_uk/variables/input/dla_sc_category.py @@ -16,9 +16,7 @@ class dla_sc_category(Variable): def formula(person, period, parameters): dla_sc = parameters(period).baseline.gov.dwp.dla.self_care SAFETY_MARGIN = 0.1 # Survey reported values could be slightly below eligible values when they should be above due to data manipulation - reported_weekly_dla_sc = ( - person("dla_sc_reported", period) / WEEKS_IN_YEAR - ) + reported_weekly_dla_sc = person("dla_sc_reported", period) / WEEKS_IN_YEAR return select( [ reported_weekly_dla_sc >= dla_sc.higher * (1 - SAFETY_MARGIN), diff --git a/policyengine_uk/variables/input/non_residential_property_value.py b/policyengine_uk/variables/input/non_residential_property_value.py index 2ab290a0d..0e7b313e6 100644 --- a/policyengine_uk/variables/input/non_residential_property_value.py +++ b/policyengine_uk/variables/input/non_residential_property_value.py @@ -3,9 +3,7 @@ class non_residential_property_value(Variable): label = "non-residential property value" - documentation = ( - "Total value of all non-residential property owned by the household" - ) + documentation = "Total value of all non-residential property owned by the household" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/input/other_residential_property_value.py b/policyengine_uk/variables/input/other_residential_property_value.py index c09361374..7e98e5d86 100644 --- a/policyengine_uk/variables/input/other_residential_property_value.py +++ b/policyengine_uk/variables/input/other_residential_property_value.py @@ -3,9 +3,7 @@ class other_residential_property_value(Variable): label = "other residence value" - documentation = ( - "Total value of all residential property owned by the household" - ) + documentation = "Total value of all residential property owned by the household" entity = Household definition_period = YEAR value_type = float diff --git a/policyengine_uk/variables/input/pension_income.py b/policyengine_uk/variables/input/pension_income.py index 0e0da6b1c..45959adff 100644 --- a/policyengine_uk/variables/input/pension_income.py +++ b/policyengine_uk/variables/input/pension_income.py @@ -6,7 +6,9 @@ class pension_income(Variable): value_type = float entity = Person label = "pension income" - documentation = "Income from private or occupational pensions (not including the State Pension)" + documentation = ( + "Income from private or occupational pensions (not including the State Pension)" + ) definition_period = YEAR unit = GBP reference = "Income Tax (Earnings and Pensions) Act 2003 s. 1(1)(b)" diff --git a/policyengine_uk/variables/input/pip_dl_category.py b/policyengine_uk/variables/input/pip_dl_category.py index fe1c561be..06920b522 100644 --- a/policyengine_uk/variables/input/pip_dl_category.py +++ b/policyengine_uk/variables/input/pip_dl_category.py @@ -14,15 +14,11 @@ class pip_dl_category(Variable): def formula(person, period, parameters): pip_dl = parameters(period).baseline.gov.dwp.pip.daily_living SAFETY_MARGIN = 0.1 # Survey reported values could be slightly below eligible values when they should be above due to data manipulation - reported_weekly_pip_dl = ( - person("pip_dl_reported", period) / WEEKS_IN_YEAR - ) + reported_weekly_pip_dl = person("pip_dl_reported", period) / WEEKS_IN_YEAR return select( [ - reported_weekly_pip_dl - >= pip_dl.enhanced * (1 - SAFETY_MARGIN), - reported_weekly_pip_dl - >= pip_dl.standard * (1 - SAFETY_MARGIN), + reported_weekly_pip_dl >= pip_dl.enhanced * (1 - SAFETY_MARGIN), + reported_weekly_pip_dl >= pip_dl.standard * (1 - SAFETY_MARGIN), True, ], [ diff --git a/policyengine_uk/variables/input/pip_m_category.py b/policyengine_uk/variables/input/pip_m_category.py index b4082ef1a..15ddbbdba 100644 --- a/policyengine_uk/variables/input/pip_m_category.py +++ b/policyengine_uk/variables/input/pip_m_category.py @@ -14,9 +14,7 @@ class pip_m_category(Variable): def formula(person, period, parameters): pip_m = parameters(period).baseline.gov.dwp.pip.mobility SAFETY_MARGIN = 0.1 # Survey reported values could be slightly below eligible values when they should be above due to data manipulation - reported_weekly_pip_m = ( - person("pip_m_reported", period) / WEEKS_IN_YEAR - ) + reported_weekly_pip_m = person("pip_m_reported", period) / WEEKS_IN_YEAR return select( [ reported_weekly_pip_m >= pip_m.enhanced * (1 - SAFETY_MARGIN), diff --git a/policyengine_uk/variables/input/private_pension_income.py b/policyengine_uk/variables/input/private_pension_income.py index de0fa5917..6230cc381 100644 --- a/policyengine_uk/variables/input/private_pension_income.py +++ b/policyengine_uk/variables/input/private_pension_income.py @@ -5,7 +5,9 @@ class private_pension_income(Variable): value_type = float entity = Person label = "pension income" - documentation = "Income from private or occupational pensions (not including the State Pension)" + documentation = ( + "Income from private or occupational pensions (not including the State Pension)" + ) definition_period = YEAR unit = GBP reference = "Income Tax (Earnings and Pensions) Act 2003 s. 1(1)(b)" diff --git a/policyengine_uk/variables/input/rent.py b/policyengine_uk/variables/input/rent.py index 2babbba07..51102b3d7 100644 --- a/policyengine_uk/variables/input/rent.py +++ b/policyengine_uk/variables/input/rent.py @@ -3,9 +3,7 @@ class rent(Variable): label = "Rent" - documentation = ( - "The total amount of rent paid by the household in the year." - ) + documentation = "The total amount of rent paid by the household in the year." entity = Household definition_period = YEAR value_type = float diff --git a/pyproject.toml b/pyproject.toml index bc1c2c1aa..3dd402e30 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ packages = ["policyengine_uk"] [project.optional-dependencies] dev = [ - "black", + "ruff>=0.9.0", "coverage", "furo<2023", "tqdm", @@ -66,7 +66,6 @@ dev = [ "yaml-changelog>=0.1.7", "snowballstemmer>=2,<3", "jupyter-book>=2.0.0a0", - "linecheck", "rich", "towncrier>=24.8.0", ] @@ -108,3 +107,9 @@ showcontent = true directory = "removed" name = "Removed" showcontent = true + +[tool.ruff] +line-length = 88 +extend-exclude = [ + "docs/book/programs/gov/dfe/care-to-learn.ipynb", +]