Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def get_current_version(pyproject_path: Path) -> str:

def infer_bump(changelog_dir: Path) -> str:
fragments = [
f
for f in changelog_dir.iterdir()
if f.is_file() and f.name != ".gitkeep"
f for f in changelog_dir.iterdir() if f.is_file() and f.name != ".gitkeep"
]
if not fragments:
print("No changelog fragments found", file=sys.stderr)
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: pip install ruff
- name: Check formatting
uses: "lgeiger/black-action@master"
with:
args: ". -l 79 --check"
run: ruff format --check .
check-changelog:
name: Check changelog fragment
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
&& (github.event.head_commit.message == 'Update PolicyEngine Nigeria')
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: pip install ruff
- name: Check formatting
uses: "lgeiger/black-action@master"
with:
args: ". -l 79 --check"
run: ruff format --check .
versioning:
name: Update versioning
if: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ documentation:
myst build docs

format:
black . -l 79
ruff format .

install:
pip install -e .[dev]
Expand Down
1 change: 1 addition & 0 deletions changelog.d/switch-to-ruff.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch from black to ruff format.
14 changes: 5 additions & 9 deletions docs/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def calculate(household: dict, reform: dict) -> dict:
if any([math.isinf(value) for value in result]):
raise ValueError("Infinite value")
else:
household[entity_plural][entity_id][variable_name][
period
] = result
household[entity_plural][entity_id][variable_name][period] = result
else:
entity_index = population.get_index(entity_id)
if variable.value_type == Enum:
Expand All @@ -86,17 +84,15 @@ def calculate(household: dict, reform: dict) -> dict:
else:
entity_result = result.tolist()[entity_index]

household[entity_plural][entity_id][variable_name][
period
] = entity_result
household[entity_plural][entity_id][variable_name][period] = (
entity_result
)
except Exception as e:
if "axes" in household:
pass
else:
logging.warn(f"Error computing {variable_name}: {e}")
household[entity_plural][entity_id][variable_name][
period
] = None
household[entity_plural][entity_id][variable_name][period] = None

return household

Expand Down
16 changes: 4 additions & 12 deletions policyengine_ng/variables/marginal_tax_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ def formula(person, period, parameters):
simulation = person.simulation
adult_index_values = person("adult_index", period)
DELTA = 1_000
mtr_adult_count = parameters(
period
).simulation.marginal_tax_rate_adults
mtr_adult_count = parameters(period).simulation.marginal_tax_rate_adults
print(simulation.input_variables)
for adult_index in range(1, 1 + mtr_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:
if variable not in simulation.input_variables:
Expand All @@ -31,15 +27,11 @@ 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)
print(household_net_income)
print(household_net_income_higher_earnings)
Expand Down
5 changes: 1 addition & 4 deletions policyengine_ng/variables/tax/is_tax_exempt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ def formula(person, period, parameters):
)
gross_income = person("gross_income", period)
has_non_employment_income = gross_income > employment_income
return (
employment_income_at_or_below_threshold
& ~has_non_employment_income
)
return employment_income_at_or_below_threshold & ~has_non_employment_income
4 changes: 1 addition & 3 deletions policyengine_ng/variables/tax/taxable_income.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ class taxable_income(Variable):

def formula(person, period, parameters):
gross_income = person("gross_income", period)
consolidated_relief_allowance = person(
"consolidated_relief_allowance", period
)
consolidated_relief_allowance = person("consolidated_relief_allowance", period)
return max_(0, gross_income - consolidated_relief_allowance)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dev = [
"build",
"jupyter-book>=1.0.4",
"mystmd>=1.3.17",
"ruff>=0.9.0",
"towncrier>=24.8.0",
]

Expand Down
Loading