Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaces: Renamings #805

Open
wants to merge 19 commits into
base: collect-components-of-namespaces
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
75b589f
Commit to create PR.
MImmesberger Dec 19, 2024
ce43ec4
Distribute taxes across new modules.
MImmesberger Dec 20, 2024
fcf9704
Continue with splitting up modules. Stopped after Wohngeld.
MImmesberger Dec 20, 2024
7bd7fcb
Also distribute ALG II functions to modules.
MImmesberger Dec 20, 2024
13cb3c7
Finish allocation to new modules.
MImmesberger Dec 20, 2024
1dac796
Add new modules to function index.
MImmesberger Dec 20, 2024
45b00a1
Adjust import path in test.
MImmesberger Dec 20, 2024
a3d0c43
Renamings in ESt modules. Also, improve structure in Vorsorgeaufwand …
MImmesberger Dec 21, 2024
37bd1cb
Renamings in Lohnsteuer module.
MImmesberger Dec 21, 2024
7f9df18
Einkommensgrenzen and Abgeltungssteuer.
MImmesberger Dec 21, 2024
7b56870
Sozialversicherungsbeiträge. Pre-commits fail due to too long qualifi…
MImmesberger Dec 21, 2024
0a29c3b
Merge remote-tracking branch 'origin/collect-components-of-namespaces…
MImmesberger Feb 18, 2025
8202de0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 18, 2025
90d22ed
Rename __init__.py to dir name.
MImmesberger Feb 21, 2025
1df1aba
Add import statements for policy_function. Also attach some noqas to …
MImmesberger Feb 21, 2025
dfd28a7
Fix remaining hook complaints.
MImmesberger Feb 22, 2025
d5f514d
Fix some small typos and add hook ignores.
MImmesberger Feb 22, 2025
88708dc
Func renamings for Vorrangpr, Unterhalt, Unterhaltsvors, KiG, Kinderb…
MImmesberger Feb 22, 2025
a5ad6cb
Merge remote-tracking branch 'origin/collect-components-of-namespaces…
MImmesberger Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions docs/geps/gep-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ GETTSIM knows about the following units:
(§5 WoGG).
- `wthh_id`: Wohngeldrechtlicher Teilhaushalt, i.e. members of a household for whom the
priority check for Wohngeld/ALG2 yields the same result ∈ {True, False}. This unit is
based on the priority check via `wohngeld_vorrang_bg` and
`wohngeld_kinderzuschl_vorrang_bg`.
based on the priority check via `vorrangpruefungen__wohngeld_vorrang_bg` and
`vorrangpruefungen__wohngeld_kinderzuschlag_vorrang_bg`.
- `fg_id`: Familiengemeinschaft. Maximum of two generations, the relevant unit for
Bürgergeld / Arbeitslosengeld 2. Another way to think about this is the potential
Bedarfsgemeinschaft before making checks for whether children have enough income fend
Expand Down
2 changes: 1 addition & 1 deletion docs/geps/gep-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ necessary inside the functions. The important changes include:
- Parameters for piecewise polynomials are parsed.
- Parameters that are derived from other parameters are calculated (examples include
`kinderzuschlag_max` starting in 2021 or calculating the phasing in of
`vorsorgeaufw_alter` over the 2005-2025 period).
`vorsorgeaufwand_alter` over the 2005-2025 period).

These functions will be avaiable to users en bloque or one-by-one so they can specify
parameters as in the YAML file for their own policy parameters.
Expand Down
68 changes: 37 additions & 31 deletions docs/geps/gep-04.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ GETTSIM; this is irrelevant for the DAG.
Function arguments can be of three kinds:

- User-provided input variables (e.g., `bruttolohn_m`).
- Outputs of other functions in the taxes and transfers system (e.g., `eink_st_y_sn`).
- Outputs of other functions in the taxes and transfers system (e.g.,
`taxes__einkommensteuer__betrag_y_sn`).
- Parameters of the taxes and transfers system, which are pre-defined and always end in
`_params` (e.g., `ges_rentenv_params`).

Expand All @@ -80,44 +81,47 @@ is able to replace this function with her own version.
See the following example for capital income taxes.

```python
def abgelt_st_y_sn(zu_verst_kapitaleink_y_sn: float, abgelt_st_params: dict) -> float:
def abgeltungssteuer__betrag_y_sn(
abgeltungssteuer__kapitaleinkommen_y_sn: float, abgelt_st_params: dict
) -> float:
"""Calculate Abgeltungssteuer on Steuernummer-level.

Parameters
----------
zu_verst_kapitaleink_y_sn
See :func:`zu_verst_kapitaleink_y_sn`.
abgeltungssteuer__kapitaleinkommen_y_sn
See :func:`abgeltungssteuer__kapitaleinkommen_y_sn`.
abgelt_st_params
See params documentation :ref:`abgelt_st_params <abgelt_st_params>`.

Returns
-------

"""
return abgelt_st_params["satz"] * zu_verst_kapitaleink_y_sn
return abgelt_st_params["satz"] * abgeltungssteuer__kapitaleinkommen_y_sn
```

The function {func}`abgelt_st_y_sn` requires the variable `zu_verst_kapital_eink_y_sn`,
which is the amount of taxable capital income on the Steuernummer-level (the latter is
implied by the `_sn` suffix, see {ref}`gep-1`). `zu_verst_kapital_eink_y_sn` must be
provided by the user as a column of the input data or it has to be the name of another
function. It is also possible to specify `zu_verst_kapital_eink_y` and aggregation to
the `sn`-level will happen automatically. `abgelt_st_params` is a dictionary of
parameters related to the calculation of `abgelt_st_y_sn`.
The function {func}`abgeltungssteuer__betrag_y_sn` requires the variable
`zu_verst_kapital_eink_y_sn`, which is the amount of taxable capital income on the
Steuernummer-level (the latter is implied by the `_sn` suffix, see {ref}`gep-1`).
`zu_verst_kapital_eink_y_sn` must be provided by the user as a column of the input data
or it has to be the name of another function. It is also possible to specify
`zu_verst_kapital_eink_y` and aggregation to the `sn`-level will happen automatically.
`abgelt_st_params` is a dictionary of parameters related to the calculation of
`abgeltungssteuer__betrag_y_sn`.

Another function, say

```python
def soli_st_y_sn(
eink_st_mit_kinderfreib_y_sn: float,
def taxes__einkommensteuer__solidaritaetszuschlag__betrag_y_sn(
taxes__einkommensteuer__betrag_mit_kinderfreib_y_sn: float,
anz_personen_sn: int,
abgelt_st_y_sn: float,
abgeltungssteuer__betrag_y_sn: float,
soli_st_params: dict,
) -> float: ...
```

may use `abgelt_st_y_sn` as an input argument. The DAG backend ensures that the function
`abgelt_st_y_sn` will be executed first.
may use `abgeltungssteuer__betrag_y_sn` as an input argument. The DAG backend ensures
that the function `abgeltungssteuer__betrag_y_sn` will be executed first.

Note that the type annotations (e.g. `float`) indicate the expected type of each input
and the output of a function, see {ref}`gep-2`.
Expand Down Expand Up @@ -249,27 +253,28 @@ Automatic summation will only happen in case no column `my_col_hh` is explicitly
Using a different reduction function than the sum is as easy as explicitly specifying
`my_col_hh`.

Consider the following example: the function `kindergeld_m` calculates the
Consider the following example: the function `kindergeld__betrag_m` calculates the
individual-level child benefit payment. `arbeitsl_geld_2_m_bg` calculates
Arbeitslosengeld 2 on the Bedarfsgemeinschaft (bg) level (as indicated by the suffix).
One necessary input of this function is the sum of all child benefits on the
Bedarfsgemeinschaft level. There is no function or input column `kindergeld_m_bg`.
Bedarfsgemeinschaft level. There is no function or input column
`kindergeld__betrag_m_bg`.

By including `kindergeld_m_bg` as an argument in the definition of
By including `kindergeld__betrag_m_bg` as an argument in the definition of
`arbeitsl_geld_2_m_bg` as follows:

```python
def arbeitsl_geld_2_m_bg(kindergeld_m_bg, other_arguments): ...
def arbeitsl_geld_2_m_bg(kindergeld__betrag_m_bg, other_arguments): ...
```

a node `kindergeld_m_bg` containing the Bedarfsgemeinschaft-level sum of `kindergeld_m`
will be automatically added to the graph. Its parents in the graph will be
`kindergeld_m` and `bg_id`. This is the same as specifying:
a node `kindergeld__betrag_m_bg` containing the Bedarfsgemeinschaft-level sum of
`kindergeld__betrag_m` will be automatically added to the graph. Its parents in the
graph will be `kindergeld__betrag_m` and `bg_id`. This is the same as specifying:

```
aggregate_by_group_kindergeld = = {
"kindergeld_m_bg": {
"source_col": "kindergeld_m",
"kindergeld__betrag_m_bg": {
"source_col": "kindergeld__betrag_m",
"aggr": "sum"
}
}
Expand Down Expand Up @@ -301,17 +306,18 @@ For example, in `kindergeld.py`, we could have:

```
aggregate_by_p_id_kindergeld = {
"kindergeld_anz_ansprüche": {
"kindergeld__anzahl_ansprüche": {
"p_id_to_aggregate_by": "p_id_kindergeld_empf",
"source_col": "kindergeld_anspruch",
"source_col": "kindergeld__anspruchsberechtigt",
"aggr": "sum",
},
}
```

This dict creates a target function `kindergeld_anz_ansprüche` which gives the amount of
claims that a person has on Kindergeld, based on the `kindergeld_anspruch` function
which returns Booleans, which show whether a child is a reason for a Kindergeld claim.
This dict creates a target function `kindergeld__anzahl_ansprüche` which gives the
amount of claims that a person has on Kindergeld, based on the
`kindergeld__anspruchsberechtigt` function which returns Booleans, which show whether a
child is a reason for a Kindergeld claim.

The output type will be the same as the input type. Exceptions:

Expand Down
3 changes: 2 additions & 1 deletion docs/gettsim_developer/hh_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ The units are:

#### Pointers

- `p_id_kinderfreib_empfänger_1` and `p_id_kinderfreib_empfänger_2` (either set by the
- `einkommensteuer__freibetraege__kinderfreibetrag__p_id_empfänger_1` and
`einkommensteuer__freibetraege__kinderfreibetrag__p_id_empfänger_2` (either set by the
user or calculated endogenously via `p_id_elternteil_1` and `p_id_elternteil_2`)

## Kindergeld
Expand Down
4 changes: 2 additions & 2 deletions docs/gettsim_objects/input_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ Has kids (incl. not in hh)

Type: bool

(betreuungskost_m)=
(betreuungskosten_m)=

## `betreuungskost_m`
## `betreuungskosten_m`

Monthly childcare expenses for a particular child under the age of 14

Expand Down
24 changes: 12 additions & 12 deletions docs/gettsim_objects/variables_out.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ You can find their individual calculation in the documentation of all {ref}`func
```{list-table}
* - Variables
- Description
* - {func}`ges_rentenv_beitr_arbeitnehmer_m <_gettsim.functions.all_functions_for_docs.ges_rentenv_beitr_arbeitnehmer_m>`
* - {func}`sozialversicherungsbeitraege__rentenversicherung__betrag_arbeitnehmer_m <_gettsim.functions.all_functions_for_docs.sozialversicherungsbeitraege__rentenversicherung__betrag_arbeitnehmer_m>`
- Monthly amount employee old-age pensions contributions
* - {func}`arbeitsl_v_beitr_arbeitnehmer_m <_gettsim.functions.all_functions_for_docs.arbeitsl_v_beitr_arbeitnehmer_m>`
* - {func}`sozialversicherungsbeitraege__arbeitslosenversicherung__betrag_arbeitnehmer_m <_gettsim.functions.all_functions_for_docs.sozialversicherungsbeitraege__arbeitslosenversicherung__betrag_arbeitnehmer_m>`
- Monthly amount employee unempl. insurance contributions
* - {func}`ges_krankenv_beitr_arbeitnehmer_m <_gettsim.functions.all_functions_for_docs.ges_krankenv_beitr_arbeitnehmer_m>`
* - {func}`sozialversicherungsbeitraege__krankenversicherung__betrag_arbeitnehmer_m <_gettsim.functions.all_functions_for_docs.sozialversicherungsbeitraege__krankenversicherung__betrag_arbeitnehmer_m>`
- Monthly amount employee health insurance contributions
* - {func}`ges_pflegev_beitr_arbeitnehmer_m <_gettsim.functions.all_functions_for_docs.ges_pflegev_beitr_arbeitnehmer_m>`
* - {func}`sozialversicherungsbeitraege__pflegeversicherung__betrag_m <_gettsim.functions.all_functions_for_docs.sozialversicherungsbeitraege__pflegeversicherung__betrag_m>`
- Monthly amount of long term care insurance
* - {func}`arbeitsl_geld_m <_gettsim.functions.all_functions_for_docs.arbeitsl_geld_m>`
* - {func}`arbeitslosengeld__betrag_m <_gettsim.functions.all_functions_for_docs.arbeitslosengeld__betrag_m>`
- Monthly amount of unemployment assistance
* - {func}`entgeltp_update <_gettsim.functions.all_functions_for_docs.entgeltp_update>`
- Updated earning points for pension claim
* - {func}`abgelt_st_y_sn <_gettsim.functions.all_functions_for_docs.abgelt_st_y_sn>`
* - {func}`abgeltungssteuer__betrag_y_sn <_gettsim.functions.all_functions_for_docs.abgeltungssteuer__betrag_y_sn>`
- Capital income tax on Steuernummer level
* - {func}`soli_st_y_sn <_gettsim.functions.all_functions_for_docs.soli_st_y_sn>`
* - {func}`taxes__einkommensteuer__solidaritaetszuschlag__betrag_y_sn <_gettsim.functions.all_functions_for_docs.taxes__einkommensteuer__solidaritaetszuschlag__betrag_y_sn>`
- Solidarity surcharge on Steuernummer level
* - {func}`kindergeld_m <_gettsim.functions.all_functions_for_docs.kindergeld_m>`
* - {func}`kindergeld__betrag_m <_gettsim.functions.all_functions_for_docs.kindergeld__betrag_m>`
- Monthly child benefit
* - {func}`eink_st_y_sn <_gettsim.functions.all_functions_for_docs.eink_st_y_sn>`
* - {func}`taxes__einkommensteuer__betrag_y_sn <_gettsim.functions.all_functions_for_docs.taxes__einkommensteuer__betrag_y_sn>`
- Income Tax on Steuernummer level
* - {func}`lohnst_m` <_gettsim.functions.all_functions_for_docs.lohnst_m>`
* - {func}`lohnsteuer__betrag_m` <_gettsim.functions.all_functions_for_docs.lohnsteuer__betrag_m>`
- Withholding tax
* - {func}`soli_st_lohnst_m <_gettsim.functions.all_functions_for_docs.soli_st_lohnst_m>`
* - {func}`lohnsteuer__betrag_soli_m <_gettsim.functions.all_functions_for_docs.lohnsteuer__betrag_soli_m>`
- Solidarity surcharge on withholding tax
* - {func}`unterhaltsvors_m <_gettsim.functions.all_functions_for_docs.unterhaltsvors_m>`
* - {func}`unterhaltsvorschuss__betrag_m <_gettsim.functions.all_functions_for_docs.unterhaltsvorschuss__betrag_m>`
- Alimony advance payment
* - {func}`arbeitsl_geld_2_m_bg <_gettsim.functions.all_functions_for_docs.arbeitsl_geld_2_m_bg>`
- Monthly subsistence payment on household level
Expand Down
34 changes: 17 additions & 17 deletions docs/how_to_guides/different_ways_to_load_policy_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"source": [
"## A Single Function\n",
"\n",
"One way to pass a single function to the tax and transfer system is alongside the `policy_functions`. As an example, we create a function called `kindergeld_m`. The function has no body because it is irrelevant for this guide. The function can be passed to `compute_taxes_and_transfers` alongside the `policy_functions` by placing both objects in a list."
"One way to pass a single function to the tax and transfer system is alongside the `policy_functions`. As an example, we create a function called `kindergeld__betrag_m`. The function has no body because it is irrelevant for this guide. The function can be passed to `compute_taxes_and_transfers` alongside the `policy_functions` by placing both objects in a list."
]
},
{
Expand All @@ -51,7 +51,7 @@
"metadata": {},
"outputs": [],
"source": [
"def kindergeld_m():\n",
"def kindergeld__betrag_m():\n",
" pass"
]
},
Expand All @@ -65,37 +65,37 @@
"df = compute_taxes_and_transfers(\n",
" data=data,\n",
" params=policy_params,\n",
" functions=[policy_functions, kindergeld_m],\n",
" targets=\"kindergeld_m_hh\",\n",
" functions=[policy_functions, kindergeld__betrag_m],\n",
" targets=\"kindergeld__betrag_m_hh\",\n",
")\n",
"```\n",
"\n",
"There are three important points.\n",
"\n",
"1. Note that, `kindergeld_m_hh` has the same function name as a [pre-defined function](https://gettsim.readthedocs.io/en/stable/gettsim_objects/functions.html#gettsim.functions.kindergeld_m_hh) inside gettsim. Thus, the internal function will be replaced with this version.\n",
"1. Note that, `kindergeld__betrag_m_hh` has the same function name as a [pre-defined function](https://gettsim.readthedocs.io/en/stable/gettsim_objects/functions.html#gettsim.functions.kindergeld__betrag_m_hh) inside gettsim. Thus, the internal function will be replaced with this version.\n",
"\n",
"2. In general, if there are multiple functions with the same name, internal functions have the lowest precedence. After that, the elements in the list passed to the `functions` argument are evaluated element by element. The leftmost element has the lowest precedence and the rightmost element the highest.\n",
"\n",
"3. If `policy_functions` would not be necessary for this example, you can also directly pass the `kindergeld_m` function to the `functions` argument.\n",
"3. If `policy_functions` would not be necessary for this example, you can also directly pass the `kindergeld__betrag_m` function to the `functions` argument.\n",
"\n",
" ```python\n",
" df = compute_taxes_and_transfers(\n",
" ...,\n",
" functions=kindergeld_m,\n",
" functions=kindergeld__betrag_m,\n",
" ...,\n",
" )\n",
" ```\n",
" \n",
"## Multiple Functions\n",
"\n",
"If you want to pass multiple functions to `compute_taxes_and_transfers`, add all functions to the list. Assume we also want to override `kindergeld_m` and have a function for that as well. Then, the call looks like this:\n",
"If you want to pass multiple functions to `compute_taxes_and_transfers`, add all functions to the list. Assume we also want to override `kindergeld__betrag_m` and have a function for that as well. Then, the call looks like this:\n",
"\n",
"```python\n",
"df = compute_taxes_and_transfers(\n",
" data=data,\n",
" params=policy_params,\n",
" functions=[policy_functions, kindergeld_m_hh, kindergeld_m],\n",
" targets=\"kindergeld_m\",\n",
" functions=[policy_functions, kindergeld__betrag_m_hh, kindergeld__betrag_m],\n",
" targets=\"kindergeld__betrag_m\",\n",
")\n",
"```"
]
Expand All @@ -118,33 +118,33 @@
"# Content of kindergeld.py\n",
"\n",
"\n",
"def kindergeld_m_hh_constant_per_hh():\n",
"def kindergeld__betrag_m_hh_constant_per_hh():\n",
" pass\n",
"\n",
"\n",
"def kindergeld_m_hh_constant_per_child():\n",
"def kindergeld__betrag_m_hh_constant_per_child():\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since the functions do not have the same name as the original function `kindergeld_m_hh`, they would not override this function if we pass one of them to `compute_taxes_and_transfers`. To solve this issue, we can use dictionaries.\n",
"Since the functions do not have the same name as the original function `kindergeld__betrag_m_hh`, they would not override this function if we pass one of them to `compute_taxes_and_transfers`. To solve this issue, we can use dictionaries.\n",
"\n",
"The keys of the dictionary are the names which will be used for the functions which are the values of the dictionary. The following code snippet shows the pseudo-code for the task (note that the index of `simulated_data` would eventually contain repeated values, in an actual application you would want to add a level indicating the type of function used):\n",
"\n",
"```python\n",
"simulated_data = []\n",
"for func in [\n",
" kindergeld_m_hh_constant_per_hh,\n",
" kindergeld_m_hh_constant_per_child,\n",
" kindergeld__betrag_m_hh_constant_per_hh,\n",
" kindergeld__betrag_m_hh_constant_per_child,\n",
"]:\n",
" df = compute_taxes_and_transfers(\n",
" data=data,\n",
" params=policy_params,\n",
" functions=[policy_functions, {\"kindergeld_m_hh\": func}],\n",
" targets=\"kindergeld_m\",\n",
" functions=[policy_functions, {\"kindergeld__betrag_m_hh\": func}],\n",
" targets=\"kindergeld__betrag_m\",\n",
" )\n",
" simulated_data = pd.concat(objs=[simulated_data, df])\n",
"```"
Expand Down
Loading
Loading