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
6 changes: 3 additions & 3 deletions outdated_docs/tutorials/policy_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
"source": [
"def arbeitslosengeld_2__betrag_m_bg(\n",
" arbeitslosengeld_2__anspruchshöhe_m_bg,\n",
" erwachsene_alle_rentenbezieher_hh,\n",
" volljährige_alle_rentenbezieher_hh,\n",
"):\n",
" if erwachsene_alle_rentenbezieher_hh:\n",
" if volljährige_alle_rentenbezieher_hh:\n",
" out = 0.0\n",
" else:\n",
" out = arbeitslosengeld_2__anspruchshöhe_m_bg\n",
Expand Down Expand Up @@ -370,7 +370,7 @@
"aggregate_by_p_id_kindergeld = {\n",
" \"kindergeld__anzahl_ansprüche\": {\n",
" \"p_id_to_aggregate_by\": \"kindergeld__p_id_empfänger\",\n",
" \"source\": \"kindergeld__grundsätzlich_anspruchsberechtigt\",\n",
" \"source\": \"kindergeld__ist_leistungsbegründendes_kind\",\n",
" \"agg\": \"sum\",\n",
" },\n",
"}\n",
Expand Down
114 changes: 70 additions & 44 deletions src/_gettsim/arbeitslosengeld_2/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,85 @@

from __future__ import annotations

from ttsim.tt_dag_elements import AggType, agg_by_group_function
from typing import TYPE_CHECKING

from ttsim.tt_dag_elements import (
AggType,
agg_by_group_function,
join,
policy_function,
)

if TYPE_CHECKING:
from ttsim.tt_dag_elements.typing import BoolColumn, IntColumn, ModuleType

Check warning on line 15 in src/_gettsim/arbeitslosengeld_2/aggregations.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/aggregations.py#L15

Added line #L15 was not covered by tests


@policy_function(start_date="2005-01-01")
def ist_kind_in_bedarfsgemeinschaft(
familie__p_id_elternteil_1: IntColumn,
familie__p_id_elternteil_2: IntColumn,
p_id: IntColumn,
bg_id: IntColumn,
xnp: ModuleType,
) -> BoolColumn:
"""Child in a Bedarfsgemeinschaft."""
bg_id_elternteil_1 = join(

Check warning on line 27 in src/_gettsim/arbeitslosengeld_2/aggregations.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/aggregations.py#L27

Added line #L27 was not covered by tests
foreign_key=familie__p_id_elternteil_1,
primary_key=p_id,
target=bg_id,
value_if_foreign_key_is_missing=-1,
xnp=xnp,
)
bg_id_elternteil_2 = join(

Check warning on line 34 in src/_gettsim/arbeitslosengeld_2/aggregations.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/aggregations.py#L34

Added line #L34 was not covered by tests
foreign_key=familie__p_id_elternteil_2,
primary_key=p_id,
target=bg_id,
value_if_foreign_key_is_missing=-1,
xnp=xnp,
)
in_gleicher_fg_wie_elternteil_1 = bg_id_elternteil_1 == bg_id
in_gleicher_fg_wie_elternteil_2 = bg_id_elternteil_2 == bg_id
return in_gleicher_fg_wie_elternteil_1 | in_gleicher_fg_wie_elternteil_2

Check warning on line 43 in src/_gettsim/arbeitslosengeld_2/aggregations.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/aggregations.py#L41-L43

Added lines #L41 - L43 were not covered by tests


@policy_function(start_date="2005-01-01")
def ist_erwachsener_in_bedarfsgemeinschaft(
ist_kind_in_bedarfsgemeinschaft: bool,
) -> bool:
"""Adult in a Bedarfsgemeinschaft."""
return not ist_kind_in_bedarfsgemeinschaft

Check warning on line 51 in src/_gettsim/arbeitslosengeld_2/aggregations.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/aggregations.py#L51

Added line #L51 was not covered by tests


# TODO(@MImmesberger): Many of these keys can go once we have `_eg` for SGB XII.
# https://github.com/iza-institute-of-labor-economics/gettsim/issues/738
@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_erwachsene_fg(familie__erwachsen: bool, fg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_kinder_fg(familie__kind: bool, fg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_kinder_bis_6_fg(familie__kind_bis_6: bool, fg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_kinder_bis_15_fg(familie__kind_bis_15: bool, fg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_kinder_bis_17_fg(familie__kind_bis_17: bool, fg_id: int) -> int:
@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.COUNT)
def anzahl_personen_bg(bg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_erwachsene_bg(familie__erwachsen: bool, bg_id: int) -> int:
def anzahl_erwachsene_bg(
ist_erwachsener_in_bedarfsgemeinschaft: bool,
bg_id: int,
) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_kinder_bg(familie__kind: bool, bg_id: int) -> int:
def anzahl_kinder_bg(ist_kind_in_bedarfsgemeinschaft: bool, bg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.COUNT)
def anzahl_personen_bg(bg_id: int) -> int:
pass
@policy_function(start_date="2005-01-01")
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)

Check warning on line 77 in src/_gettsim/arbeitslosengeld_2/aggregations.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/aggregations.py#L77

Added line #L77 was not covered by tests


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_kinder_bis_17_bg(familie__kind_bis_17: bool, bg_id: int) -> int:
def anzahl_kinder_bis_17_bg(
ist_kind_bis_17_in_bedarfsgemeinschaft: bool, bg_id: int
) -> int:
pass


Expand All @@ -57,16 +89,10 @@
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_erwachsene_eg(familie__erwachsen: bool, eg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.SUM)
def anzahl_kinder_eg(familie__kind: bool, eg_id: int) -> int:
pass


@agg_by_group_function(start_date="2005-01-01", agg_type=AggType.COUNT)
def anzahl_personen_eg(eg_id: int) -> int:
pass
@policy_function(start_date="2005-01-01")
def hat_kind_in_gleicher_bedarfsgemeinschaft(
anzahl_kinder_bg: int,
ist_erwachsener_in_bedarfsgemeinschaft: bool,
) -> bool:
"""Has a child in the same Bedarfsgemeinschaft."""
return anzahl_kinder_bg >= 1 and ist_erwachsener_in_bedarfsgemeinschaft

Check warning on line 98 in src/_gettsim/arbeitslosengeld_2/aggregations.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/aggregations.py#L98

Added line #L98 was not covered by tests
6 changes: 3 additions & 3 deletions src/_gettsim/arbeitslosengeld_2/arbeitslosengeld_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def betrag_m_bg(
vorrangprüfungen__wohngeld_vorrang_vor_arbeitslosengeld_2_bg: bool,
vorrangprüfungen__kinderzuschlag_vorrang_vor_arbeitslosengeld_2_bg: bool,
vorrangprüfungen__wohngeld_und_kinderzuschlag_vorrang_vor_arbeitslosengeld_2_bg: bool,
erwachsene_alle_rentenbezieher_hh: bool,
volljährige_alle_rentenbezieher_hh: bool,
) -> float:
"""Calculate final monthly subsistence payment on household level.

Expand All @@ -21,13 +21,13 @@ def betrag_m_bg(
# Alter (SGB XII) is implemented yet. We assume for now that households with only
# retirees are eligible for Grundsicherung im Alter but not for ALG2/Wohngeld. All
# other households are not eligible for SGB XII, but SGB II / Wohngeld. Once this is
# resolved, remove the `erwachsene_alle_rentenbezieher_hh` condition.
# resolved, remove the `volljährige_alle_rentenbezieher_hh` condition.
# https://github.com/iza-institute-of-labor-economics/gettsim/issues/703
if (
vorrangprüfungen__wohngeld_vorrang_vor_arbeitslosengeld_2_bg
or vorrangprüfungen__kinderzuschlag_vorrang_vor_arbeitslosengeld_2_bg
or vorrangprüfungen__wohngeld_und_kinderzuschlag_vorrang_vor_arbeitslosengeld_2_bg
or erwachsene_alle_rentenbezieher_hh
or volljährige_alle_rentenbezieher_hh
):
out = 0.0
else:
Expand Down
16 changes: 10 additions & 6 deletions src/_gettsim/arbeitslosengeld_2/freibeträge_vermögen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from ttsim.tt_dag_elements import policy_function


# TODO(@MImmesberger): Treatment of children who live in their own BG may be wrong here.
# https://github.com/iza-institute-of-labor-economics/gettsim/issues/1009
@policy_function(start_date="2005-01-01", end_date="2022-12-31")
def grundfreibetrag_vermögen(
familie__kind: bool,
ist_kind_in_bedarfsgemeinschaft: bool,
alter: int,
geburtsjahr: int,
maximaler_grundfreibetrag_vermögen: float,
Expand All @@ -20,7 +22,7 @@
threshold_years = list(vermögensgrundfreibetrag_je_lebensjahr.keys())
if geburtsjahr <= threshold_years[0]:
out = next(iter(vermögensgrundfreibetrag_je_lebensjahr.values())) * alter
elif (geburtsjahr >= threshold_years[1]) and (not familie__kind):
elif (geburtsjahr >= threshold_years[1]) and (not ist_kind_in_bedarfsgemeinschaft):

Check warning on line 25 in src/_gettsim/arbeitslosengeld_2/freibeträge_vermögen.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/freibeträge_vermögen.py#L25

Added line #L25 was not covered by tests
out = list(vermögensgrundfreibetrag_je_lebensjahr.values())[1] * alter
else:
out = 0.0
Expand All @@ -30,10 +32,12 @@

# TODO(@MImmesberger): Parameter should be defined as a piecewise_constant.
# https://github.com/iza-institute-of-labor-economics/gettsim/issues/911
# TODO(@MImmesberger): Treatment of children who live in their own BG may be wrong here.
# https://github.com/iza-institute-of-labor-economics/gettsim/issues/1009
@policy_function(start_date="2005-01-01", end_date="2022-12-31")
def maximaler_grundfreibetrag_vermögen(
geburtsjahr: int,
familie__kind: bool,
ist_kind_in_bedarfsgemeinschaft: bool,
obergrenze_vermögensgrundfreibetrag: dict[int, float],
) -> float:
"""Calculate maximal wealth exemptions by year of birth.
Expand All @@ -42,7 +46,7 @@
"""
threshold_years = list(obergrenze_vermögensgrundfreibetrag.keys())
obergrenzen = list(obergrenze_vermögensgrundfreibetrag.values())
if familie__kind:
if ist_kind_in_bedarfsgemeinschaft:

Check warning on line 49 in src/_gettsim/arbeitslosengeld_2/freibeträge_vermögen.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/freibeträge_vermögen.py#L49

Added line #L49 was not covered by tests
out = 0.0
else:
if geburtsjahr < threshold_years[1]:
Expand Down Expand Up @@ -101,7 +105,7 @@
def vermögensfreibetrag_bg_ab_2023(
anzahl_personen_bg: int,
vermögensfreibetrag_in_karenzzeit_bg: float,
arbeitslosengeld_2_bezug_im_vorjahr: bool,
bezug_im_vorjahr: bool,
vermögensfreibetrag_je_person_nach_karenzzeit: dict[str, float],
) -> float:
"""Calculate actual wealth exemptions since 2023.
Expand All @@ -110,7 +114,7 @@

Note: Since 2023, Arbeitslosengeld 2 is referred to as Bürgergeld.
"""
if arbeitslosengeld_2_bezug_im_vorjahr:
if bezug_im_vorjahr:

Check warning on line 117 in src/_gettsim/arbeitslosengeld_2/freibeträge_vermögen.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/freibeträge_vermögen.py#L117

Added line #L117 was not covered by tests
out = (
anzahl_personen_bg
* vermögensfreibetrag_je_person_nach_karenzzeit["normaler_satz"]
Expand Down
2 changes: 1 addition & 1 deletion src/_gettsim/arbeitslosengeld_2/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@policy_input(start_date="2023-01-01")
def bezug_im_vorjahr() -> bool:
"""Received Arbeitslosengeld II / Bürgergeld in previous year."""
"""Whether the person received Arbeitslosengeld 2 / Bürgergeld in the previous year."""


# TODO(@MImmesberger): Remove input variable eigenbedarf_gedeckt once
Expand Down
24 changes: 9 additions & 15 deletions src/_gettsim/arbeitslosengeld_2/regelbedarf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
get_consecutive_int_lookup_table_param_value,
param_function,
policy_function,
policy_input,
)

if TYPE_CHECKING:
Expand All @@ -37,9 +36,9 @@
@policy_function(start_date="2005-01-01")
def mehrbedarf_alleinerziehend_m(
familie__alleinerziehend: bool,
anzahl_kinder_bis_17_fg: int,
anzahl_kinder_bis_6_fg: int,
anzahl_kinder_bis_15_fg: int,
familie__anzahl_kinder_bis_17_fg: int,
familie__anzahl_kinder_bis_6_fg: int,
familie__anzahl_kinder_bis_15_fg: int,
parameter_mehrbedarf_alleinerziehend: dict[str, float],
) -> float:
"""Mehrbedarf (additional need) for single parents as a share of the Regelsatz.
Expand All @@ -54,13 +53,13 @@
"""
basis_mehrbedarf = (
parameter_mehrbedarf_alleinerziehend["basis_je_kind_bis_17"]
* anzahl_kinder_bis_17_fg
* familie__anzahl_kinder_bis_17_fg
)

if (
anzahl_kinder_bis_6_fg == 1
or anzahl_kinder_bis_15_fg == 2
or anzahl_kinder_bis_15_fg == 3
familie__anzahl_kinder_bis_6_fg == 1
or familie__anzahl_kinder_bis_15_fg == 2
or familie__anzahl_kinder_bis_15_fg == 3
):
mehrbedarf = max(
parameter_mehrbedarf_alleinerziehend["kind_bis_6_oder_2_3_kinder_bis_15"],
Expand Down Expand Up @@ -274,19 +273,14 @@
return berechtigte_wohnfläche * anerkannte_warmmiete_je_qm_m


@policy_input(start_date="2023-01-01")
def arbeitslosengeld_2_bezug_im_vorjahr() -> bool:
"""Whether the person received Arbeitslosengeld 2 / Bürgergeld in the previous year."""


@policy_function(
start_date="2023-01-01",
leaf_name="kosten_der_unterkunft_m",
)
def kosten_der_unterkunft_m_ab_2023(
bruttokaltmiete_m: float,
heizkosten_m: float,
arbeitslosengeld_2_bezug_im_vorjahr: bool,
bezug_im_vorjahr: bool,
berechtigte_wohnfläche: float,
anerkannte_warmmiete_je_qm_m: float,
) -> float:
Expand All @@ -296,7 +290,7 @@

Note: Since 2023, Arbeitslosengeld 2 is referred to as Bürgergeld.
"""
if arbeitslosengeld_2_bezug_im_vorjahr:
if bezug_im_vorjahr:

Check warning on line 293 in src/_gettsim/arbeitslosengeld_2/regelbedarf.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/regelbedarf.py#L293

Added line #L293 was not covered by tests
out = berechtigte_wohnfläche * anerkannte_warmmiete_je_qm_m
else:
out = bruttokaltmiete_m + heizkosten_m
Expand Down
4 changes: 2 additions & 2 deletions src/_gettsim/einkommensteuer/einkommensteuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def alleinerziehend_sn(familie__alleinerziehend: bool, sn_id: int) -> bool:

@agg_by_p_id_function(agg_type=AggType.SUM)
def anzahl_kindergeld_ansprüche_1(
kindergeld__grundsätzlich_anspruchsberechtigt: bool,
kindergeld__ist_leistungsbegründendes_kind: bool,
familie__p_id_elternteil_1: int,
p_id: int,
) -> int:
Expand All @@ -49,7 +49,7 @@ def anzahl_kindergeld_ansprüche_1(

@agg_by_p_id_function(agg_type=AggType.SUM)
def anzahl_kindergeld_ansprüche_2(
kindergeld__grundsätzlich_anspruchsberechtigt: bool,
kindergeld__ist_leistungsbegründendes_kind: bool,
familie__p_id_elternteil_2: int,
p_id: int,
) -> int:
Expand Down
4 changes: 2 additions & 2 deletions src/_gettsim/einkommensteuer/kinderfreibetrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def anzahl_kinderfreibeträge(

@agg_by_p_id_function(agg_type=AggType.SUM)
def anzahl_kinderfreibeträge_1(
kindergeld__grundsätzlich_anspruchsberechtigt: bool,
kindergeld__ist_leistungsbegründendes_kind: bool,
p_id_kinderfreibetragsempfänger_1: int,
p_id: int,
) -> int:
Expand All @@ -51,7 +51,7 @@ def anzahl_kinderfreibeträge_1(

@agg_by_p_id_function(agg_type=AggType.SUM)
def anzahl_kinderfreibeträge_2(
kindergeld__grundsätzlich_anspruchsberechtigt: bool,
kindergeld__ist_leistungsbegründendes_kind: bool,
p_id_kinderfreibetragsempfänger_2: int,
p_id: int,
) -> int:
Expand Down
Loading
Loading