Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
72 changes: 36 additions & 36 deletions pixi.lock

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ classifiers = [
]
# Dependencies and requirements
requires-python = ">=3.11"
dependencies = [ "ipywidgets", "numpy", "numpy-groupies", "pandas", "openpyxl", "pygments", "pygraphviz", "pytest", "pyyaml", "networkx>=3.5,<4", "plotly>=6.2.0,<7", "optree>=0.16.0,<0.17",
dependencies = [
"ipywidgets",
"networkx>=3.5",
"numpy-groupies",
"numpy",
"openpyxl",
"optree>=0.16.0",
"pandas",
"plotly>=6.2.0",
"pygments",
"pygraphviz",
"pytest",
"pyyaml",
]


Expand Down Expand Up @@ -214,41 +226,37 @@ extend-ignore = [
"N999", # Allow non-ASCII characters in file names.
"PLC2401", # Allow non-ASCII characters in variable names.
"PLC2403", # Allow non-ASCII function names for imports.
"PLR0913", # Allow too many arguments in function definitions.
"PLR0913", # Allow many arguments in function definitions.
"PLR5501", # elif not supported by vectorization converter for Jax
"TRY003", # Avoid specifying long messages outside the exception class

# Ignored during transition phase
# ======================================
"D", # docstrings
"INP001", # implicit namespace packages without init.
"PLR2004", # Magic values used in comparison
"PT006", # Allows only lists of tuples in parametrize, even if single argument
"PT007", # wrong type in parametrize
"S101", # use of asserts outside of tests

]
exclude = []

[tool.ruff.lint.per-file-ignores]
"conftest.py" = ["ANN"]
"docs/**/*.ipynb" = ["T201"]
"docs/*" = ["INP001", "T201"]
# Cannot have default values in test functions with fixtures -- not an issue here.
"src/gettsim/__init__.py" = ["PT028"]
# Mostly things vectorization can't handle
"src/_gettsim/*" = ["E501", "PLR1714", "PLR1716", "E721", "SIM108", "RET"]
# Lohnsteuerklassen and age groups are fine to hard-code.
"src/_gettsim/lohnsteuer/*.py" = ["PLR2004"]
"src/_gettsim/familie/familie.py" = ["PLR2004"]
# All tests return None and use asserts
"src/_gettsim_tests/**/*.py" = ["ANN", "S101"]
# Long lines.
"src/ttsim/interface_dag_elements/specialized_environment.py" = ["E501"]
"src/ttsim/interface_dag_elements/__init__.py" = ["TC"]
"src/ttsim/interface_dag_elements/fail_if.py" = ["E501"]
"src/ttsim/interface_dag_elements/typing.py" = ["PGH", "PLR", "SIM114"]
"src/ttsim/plot_dag.py" = ["FBT002"]
# Mostly things vectorization can't handle
"tests/ttsim/mettsim/**/*.py" = ["PLR1714", "PLR1716", "E721", "SIM108", "RET"]
"tests/ttsim/tt_dag_elements/test_vectorization.py" = ["PLR1714", "PLR1716", "E721", "SIM108", "RET"]
# All tests return None and use asserts
"tests/ttsim/**/*.py" = ["ANN", "S101"]
"tests/ttsim/**/*.py" = ["ANN", "INP001", "PLR2004", "S101"]
# Long lines.
"tests/ttsim/interface_dag_elements/test_failures.py" = ["E501"]
# TODO: remove once ported nicely
"src/ttsim/stale_code_storage.py" = ["ALL"]
Expand Down
2 changes: 1 addition & 1 deletion src/_gettsim/arbeitslosengeld_2/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def ist_kind_bis_17_in_bedarfsgemeinschaft(
alter: int, ist_kind_in_bedarfsgemeinschaft: bool
) -> bool:
"""Child under the age of 18 in Bedarfsgemeinschaft."""
return ist_kind_in_bedarfsgemeinschaft and (alter <= 17)
return ist_kind_in_bedarfsgemeinschaft and (alter <= 17) # noqa: PLR2004


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
Expand Down
4 changes: 2 additions & 2 deletions src/_gettsim/arbeitslosengeld_2/regelbedarf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def mehrbedarf_alleinerziehend_m(

if (
familie__anzahl_kinder_bis_6_fg == 1
or familie__anzahl_kinder_bis_15_fg == 2
or familie__anzahl_kinder_bis_15_fg == 3
or familie__anzahl_kinder_bis_15_fg == 2 # noqa: PLR2004
or familie__anzahl_kinder_bis_15_fg == 3 # noqa: PLR2004
):
mehrbedarf = max(
parameter_mehrbedarf_alleinerziehend["kind_bis_6_oder_2_3_kinder_bis_15"],
Expand Down
8 changes: 4 additions & 4 deletions src/_gettsim/einkommensteuer/abzüge/alter.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ def get_consecutive_int_1d_lookup_table_with_filled_up_tails(
right_tail_key by filling the gaps with the minimum and maximum values from the
original dictionary.
"""
if not all(isinstance(k, int) for k in raw):
raise ValueError("All dictionary keys must be integers")
min_key_in_spec = min(raw.keys())
max_key_in_spec = max(raw.keys())
assert all(isinstance(k, int) for k in raw)
assert len(list(raw.keys())) == max_key_in_spec - min_key_in_spec + 1, (
"Dictionary keys must be consecutive integers."
)
if len(list(raw.keys())) != max_key_in_spec - min_key_in_spec + 1:
raise ValueError("Dictionary keys must be consecutive integers.")
consecutive_dict_start = dict.fromkeys(
range(left_tail_key, min_key_in_spec),
raw[min_key_in_spec],
Expand Down
File renamed without changes.
7 changes: 5 additions & 2 deletions src/_gettsim/elterngeld/elterngeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ def bezugsmonate_unter_grenze_fg(
parent.

"""
if familie__alleinerziehend or bezugsmonate_partner >= 2:
if (
familie__alleinerziehend
or bezugsmonate_partner >= max_bezugsmonate["partnermonate"]
):
out = (
bisherige_bezugsmonate_fg
< max_bezugsmonate["basismonate"] + max_bezugsmonate["partnermonate"]
Expand Down Expand Up @@ -296,5 +299,5 @@ def jüngstes_kind_oder_mehrling(

"""
return (
(alter_monate - familie__alter_monate_jüngstes_mitglied_fg) < 0.1
(alter_monate - familie__alter_monate_jüngstes_mitglied_fg) < 0.1 # noqa: PLR2004
) and ist_leistungsbegründendes_kind
Empty file.
2 changes: 1 addition & 1 deletion src/_gettsim/grundsicherung/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def ist_kind_in_einstandsgemeinschaft(alter: IntColumn) -> BoolColumn:
# Einstandsgemeinschaft. This is not necessarily true. Rewrite once we refactor SGB
# XII.
# https://github.com/iza-institute-of-labor-economics/gettsim/issues/738
return alter <= 17
return alter <= 17 # noqa: PLR2004


@policy_function()
Expand Down
4 changes: 2 additions & 2 deletions src/_gettsim/ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _assign_parents_fg_id(
(p_id_elternteil_loc >= 0)
* (fg_id == p_id + p_id * n)
* (hh_id == hh_id[p_id_elternteil_loc])
* (alter < 25)
* (alter < 25) # noqa: PLR2004
* (1 - children),
fg_id[p_id_elternteil_loc],
fg_id,
Expand Down Expand Up @@ -159,7 +159,7 @@ def bg_id(
# TODO(@MImmesberger): Remove hard-coded number
# https://github.com/iza-institute-of-labor-economics/gettsim/issues/668
return xnp.where(
(arbeitslosengeld_2__eigenbedarf_gedeckt) * (alter < 25),
(arbeitslosengeld_2__eigenbedarf_gedeckt) * (alter < 25), # noqa: PLR2004
offset + p_id,
fg_id,
)
Expand Down
2 changes: 1 addition & 1 deletion src/_gettsim/individual_characteristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def alter_bis_24(alter: int) -> bool:

Trivial, but necessary in order to use the target for aggregation.
"""
return alter <= 24
return alter <= 24 # noqa: PLR2004
4 changes: 2 additions & 2 deletions src/_gettsim/kindergeld/kindergeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ def leistungsbegründendes_kind_nach_stunden(
)


@policy_function()
@policy_function(end_date="2015-12-31")
def kind_bis_10_mit_kindergeld(
alter: int,
ist_leistungsbegründendes_kind: bool,
) -> bool:
"""Child under the age of 11 and eligible for Kindergeld."""
return ist_leistungsbegründendes_kind and (alter <= 10)
return ist_leistungsbegründendes_kind and (alter <= 10) # noqa: PLR2004


@policy_function(vectorization_strategy="not_required")
Expand Down
2 changes: 1 addition & 1 deletion src/_gettsim/sozialversicherung/pflege/beitrag/beitrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def betrag_versicherter_midijob_m_mit_verringertem_beitrag_für_eltern_mit_mehre
+ sozialversicherung__midijob_bemessungsentgelt_m
* beitragssatz_nach_kinderzahl["zusatz_kinderlos"]
)
if anzahl_kinder_bis_24 >= 2:
if anzahl_kinder_bis_24 > 1:
add = add - (
sozialversicherung__beitragspflichtige_einnahmen_aus_midijob_arbeitnehmer_m
* beitragssatz_nach_kinderzahl["abschlag_für_kinder_bis_24"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def beitragssatz_arbeitnehmer_mit_abschlag_nach_kinderzahl(
add = 0.0
if zahlt_zusatzbetrag_kinderlos:
add = add + beitragssatz_nach_kinderzahl["zusatz_kinderlos"]
if anzahl_kinder_bis_24 >= 2:
if anzahl_kinder_bis_24 > 1:
add = add - beitragssatz_nach_kinderzahl["abschlag_für_kinder_bis_24"] * min(
anzahl_kinder_bis_24 - 1,
4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
mindestpflichtbeitragsmonate:
name:
de: Mindestpflichtbeitragsmonate für Erwerbsminderungsrente
en: Minimum number of required contribution months for disability pension
description:
de: >-
...
en: >-
...
unit: Months
reference_period: null
type: scalar
2001-01-01:
value: 36
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def grundsätzlich_anspruchsberechtigt(
teilweise_erwerbsgemindert: bool,
sozialversicherung__rente__pflichtbeitragsmonate: float,
sozialversicherung__rente__mindestwartezeit_erfüllt: bool,
mindestpflichtbeitragsmonate: int,
) -> bool:
"""
Eligibility for Erwerbsminderungsrente.
Expand All @@ -81,7 +82,8 @@ def grundsätzlich_anspruchsberechtigt(
anspruch_erwerbsm_rente = (
(voll_erwerbsgemindert or teilweise_erwerbsgemindert)
and sozialversicherung__rente__mindestwartezeit_erfüllt
and sozialversicherung__rente__pflichtbeitragsmonate >= 36
and sozialversicherung__rente__pflichtbeitragsmonate
>= mindestpflichtbeitragsmonate
)

return anspruch_erwerbsm_rente
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ def anzurechnendes_einkommen_m(
# singles and those for married subjects
# Note: Thresholds are defined relativ to rentenwert which is implemented by
# dividing the income by rentenwert and multiply rentenwert to the result.
if familie__anzahl_personen_ehe == 2:
if familie__anzahl_personen_ehe == 1:
out = _anzurechnendes_einkommen_m(
einkommen_m_ehe=einkommen_m_ehe,
rentenwert=sozialversicherung__rente__rentenwert,
parameter_anzurechnendes_einkommen=anzurechnendes_einkommen_mit_partner,
parameter_anzurechnendes_einkommen=anzurechnendes_einkommen_ohne_partner,
xnp=xnp,
)
else:
out = _anzurechnendes_einkommen_m(
einkommen_m_ehe=einkommen_m_ehe,
rentenwert=sozialversicherung__rente__rentenwert,
parameter_anzurechnendes_einkommen=anzurechnendes_einkommen_ohne_partner,
parameter_anzurechnendes_einkommen=anzurechnendes_einkommen_mit_partner,
xnp=xnp,
)
return out
Expand Down
Empty file added src/_gettsim/wohnen/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion src/_gettsim/wohngeld/einkommen.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from types import ModuleType


@agg_by_p_id_function(agg_type=AggType.SUM)
@agg_by_p_id_function(agg_type=AggType.SUM, end_date="2015-12-31")
def alleinerziehendenbonus(
kindergeld__kind_bis_10_mit_kindergeld: bool,
kindergeld__p_id_empfänger: int,
Expand Down
30 changes: 18 additions & 12 deletions src/_gettsim/wohngeld/miete.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def max_miete_m_lookup_mit_baujahr(
tmp = raw_max_miete_m_nach_baujahr.copy()
per_additional_person = tmp.pop("jede_weitere_person")
max_n_p_defined = max(tmp.keys())
assert all(isinstance(i, int) for i in tmp)
if not all(isinstance(i, int) for i in tmp):
raise ValueError("All keys must be integers")
baujahre = sorted(tmp[1].keys())
lookup_dict = {}
for i, baujahr in enumerate(baujahre):
Expand Down Expand Up @@ -69,7 +70,8 @@ def max_miete_m_lookup_ohne_baujahr(
expanded = raw_max_miete_m.copy()
per_additional_person = expanded.pop("jede_weitere_person")
max_n_p_defined = max(expanded.keys())
assert all(isinstance(i, int) for i in expanded)
if not all(isinstance(i, int) for i in expanded):
raise ValueError("All keys must be integers")
for n_p in range(max_n_p_defined + 1, max_anzahl_personen["indizierung"] + 1): # type: ignore[operator]
expanded[n_p] = {
ms: expanded[max_n_p_defined][ms]
Expand All @@ -87,13 +89,14 @@ def min_miete_lookup(
) -> ConsecutiveIntLookupTableParamValue:
"""Minimum rent considered in Wohngeld calculation."""
max_n_p_normal = max_anzahl_personen["normale_berechnung"]
assert max(raw_min_miete_m.keys()) == max_n_p_normal, (
"The maximum number of persons for the normal calculation of the basic"
"Wohngeld formula `max_anzahl_personen['normale_berechnung'] "
f"(got: {max_n_p_normal}) must be the same as the maximum number of household "
"members in `koeffizienten_berechnungsformel` "
f"(got: {max(raw_min_miete_m.keys())})"
)
if max(raw_min_miete_m.keys()) != max_n_p_normal:
raise ValueError(
"The maximum number of persons for the normal calculation of the basic"
"Wohngeld formula `max_anzahl_personen['normale_berechnung'] "
f"(got: {max_n_p_normal}) must be the same as the maximum number of household "
"members in `koeffizienten_berechnungsformel` "
f"(got: {max(raw_min_miete_m.keys())})"
)
expanded = raw_min_miete_m.copy()
for n_p in range(max_n_p_normal + 1, max_anzahl_personen["indizierung"] + 1):
expanded[n_p] = raw_min_miete_m[max_n_p_normal]
Expand All @@ -110,7 +113,8 @@ def heizkostenentlastung_m_lookup(
expanded = raw_heizkostenentlastung_m.copy()
per_additional_person = expanded.pop("jede_weitere_person")
max_n_p_defined = max(expanded.keys())
assert all(isinstance(i, int) for i in expanded)
if not all(isinstance(i, int) for i in expanded):
raise ValueError("All keys must be integers")
for n_p in range(max_n_p_defined + 1, max_anzahl_personen["indizierung"] + 1): # type: ignore[operator]
expanded[n_p] = (
expanded[max_n_p_defined] + (n_p - max_n_p_defined) * per_additional_person # type: ignore[operator]
Expand All @@ -128,7 +132,8 @@ def dauerhafte_heizkostenkomponente_m_lookup(
expanded = raw_dauerhafte_heizkostenkomponente_m.copy()
per_additional_person = expanded.pop("jede_weitere_person")
max_n_p_defined = max(expanded.keys())
assert all(isinstance(i, int) for i in expanded)
if not all(isinstance(i, int) for i in expanded):
raise ValueError("All keys must be integers")
for n_p in range(max_n_p_defined + 1, max_anzahl_personen["indizierung"] + 1): # type: ignore[operator]
expanded[n_p] = (
expanded[max_n_p_defined] + (n_p - max_n_p_defined) * per_additional_person # type: ignore[operator]
Expand All @@ -146,7 +151,8 @@ def klimakomponente_m_lookup(
expanded = raw_klimakomponente_m.copy()
per_additional_person = expanded.pop("jede_weitere_person")
max_n_p_defined = max(expanded.keys())
assert all(isinstance(i, int) for i in expanded)
if not all(isinstance(i, int) for i in expanded):
raise ValueError("All keys must be integers")
for n_p in range(max_n_p_defined + 1, max_anzahl_personen["indizierung"] + 1): # type: ignore[operator]
expanded[n_p] = (
expanded[max_n_p_defined] + (n_p - max_n_p_defined) * per_additional_person # type: ignore[operator]
Expand Down
13 changes: 7 additions & 6 deletions src/_gettsim/wohngeld/wohngeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ def basisformel_params(
c = {i: v["c"] for i, v in koeffizienten_berechnungsformel.items()}
max_normal = max_anzahl_personen["normale_berechnung"]
for koeff in [a, b, c]:
assert max(koeff.keys()) == max_normal, (
"The maximum number of persons for the normal calculation of the basic"
"Wohngeld formula `max_anzahl_personen['normale_berechnung'] "
f"(got: {max_normal}) must be the same as the maximum number of household "
f"members in `koeffizienten_berechnungsformel` (got: {max(koeff.keys())})"
)
if max(koeff.keys()) != max_normal:
raise ValueError(
"The maximum number of persons for the normal calculation of the basic"
"Wohngeld formula `max_anzahl_personen['normale_berechnung'] "
f"(got: {max_normal}) must be the same as the maximum number of household "
f"members in `koeffizienten_berechnungsformel` (got: {max(koeff.keys())})"
)
zusatzbetrag_nach_haushaltsgröße = dict.fromkeys(range(max_normal + 1), 0.0)
for i in range(max_normal + 1, max_anzahl_personen["indizierung"] + 1):
for koeff in [a, b, c]:
Expand Down
2 changes: 1 addition & 1 deletion src/_gettsim_tests/test_jittability.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def cached_specialized_environment(

@pytest.mark.skipif_numpy
@pytest.mark.parametrize(
"tree_path, fun",
("tree_path", "fun"),
get_orig_gettsim_column_functions(),
ids=[str(x[0]) for x in get_orig_gettsim_column_functions()],
)
Expand Down
2 changes: 1 addition & 1 deletion src/_gettsim_tests/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_policy(test: PolicyTest, backend: Literal["numpy", "jax"]):
)
def test_gettsim_policy_environment_is_complete(orig_gettsim_objects, date):
"""Test that GETTSIM's policy environment contains all root nodes of its DAG."""
if date.year < 2015:
if date.year < 2015: # noqa: PLR2004
pytest.skip(
"Policy environment for dates before 2015 are not complete. See issue #962."
)
Expand Down
3 changes: 2 additions & 1 deletion src/ttsim/interface_dag_elements/orig_policy_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def load_module(path: Path, root: Path) -> ModuleType:
_msg = f"Could not load module spec for {path}, {root}"
if spec is None:
raise ImportError(_msg)
assert spec.loader is not None, _msg
if spec.loader is None:
raise ImportError(_msg)
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)
Expand Down
Loading
Loading