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 11 commits into
base: collect-components-of-namespaces
Choose a base branch
from
  •  
  •  
  •  
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
38 changes: 21 additions & 17 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
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
18 changes: 9 additions & 9 deletions docs/gettsim_objects/variables_out.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ 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>`
- 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>`
- 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>`
- Alimony advance payment
Expand Down
52 changes: 30 additions & 22 deletions docs/how_to_guides/visualizing_the_system.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
"id": "6",
"metadata": {},
"source": [
"Functions inside GETTSIM are a little bit special. Take for example `abgelt_st_y_sn`\n",
"Functions inside GETTSIM are a little bit special. Take for example `abgeltungssteuer__betrag_y_sn`\n",
"which is documented\n",
"[here](https://gettsim.readthedocs.io/en/stable/gettsim_objects/functions.html#gettsim.functions.abgelt_st_y_sn).\n",
"[here](https://gettsim.readthedocs.io/en/stable/gettsim_objects/functions.html#gettsim.functions.abgeltungssteuer__betrag_y_sn).\n",
"The signature of the function is\n",
"\n",
"```python\n",
"def abgelt_st_y_sn(zu_verst_kapitaleink_y_sn, abgelt_st_params):\n",
"def abgeltungssteuer__betrag_y_sn(abgeltungssteuer__kapitaleinkommen_y_sn, abgelt_st_params):\n",
" pass\n",
"```\n",
"\n",
Expand All @@ -77,15 +77,15 @@
"which, in turn, also relies on some arguments.\n",
"\n",
"Here, ``abgelt_st_params`` is a paramter file which includes paramters needed to\n",
"calculate the capital income tax. ``zu_verst_kapitaleink_y_sn`` on the other hand is\n",
"calculate the capital income tax. ``abgeltungssteuer__kapitaleinkommen_y_sn`` on the other hand is\n",
"itself a function which is documented\n",
"[here](https://gettsim.readthedocs.io/en/stable/gettsim_objects/functions.html#gettsim.functions.zu_verst_kapital_eink_sn).\n",
"By using ``zu_verst_kapitaleink_y_sn`` as an argument name, GETTSIM knows to pass the\n",
"data computed by the function ``zu_verst_kapitaleink_y_sn`` to ``abgelt_st_y_sn``.\n",
"By using ``abgeltungssteuer__kapitaleinkommen_y_sn`` as an argument name, GETTSIM knows to pass the\n",
"data computed by the function ``abgeltungssteuer__kapitaleinkommen_y_sn`` to ``abgeltungssteuer__betrag_y_sn``.\n",
"\n",
"This dependency relationship can be analyzed for all functions passed to GETTSIM and be\n",
"visualized in a dag. Below you can see a plot of all variables which are directly\n",
"connected to ``zu_verst_kapitaleink_y_sn``. The arrows point from dependencies to\n",
"connected to ``abgeltungssteuer__kapitaleinkommen_y_sn``. The arrows point from dependencies to\n",
"dependents. Each node is either a functions or a variable."
]
},
Expand All @@ -98,7 +98,9 @@
"source": [
"plot_dag(\n",
" environment=environment,\n",
" selectors=[{\"node\": \"zu_verst_kapitaleink_y_sn\", \"type\": \"neighbors\"}],\n",
" selectors=[\n",
" {\"node\": \"abgeltungssteuer__kapitaleinkommen_y_sn\", \"type\": \"neighbors\"}\n",
" ],\n",
").show()"
]
},
Expand Down Expand Up @@ -153,7 +155,9 @@
"source": [
"plot_dag(\n",
" environment=environment,\n",
" selectors=[{\"node\": \"zu_verst_kapitaleink_y_sn\", \"type\": \"neighbors\"}],\n",
" selectors=[\n",
" {\"node\": \"abgeltungssteuer__kapitaleinkommen_y_sn\", \"type\": \"neighbors\"}\n",
" ],\n",
" orientation=\"h\",\n",
").show()"
]
Expand Down Expand Up @@ -183,7 +187,9 @@
"source": [
"plot_dag(\n",
" environment=environment,\n",
" selectors=[{\"node\": \"geringfügig_beschäftigt\", \"type\": \"descendants\"}],\n",
" selectors=[\n",
" {\"node\": \"einkommensgrenzen__geringfügig_beschäftigt\", \"type\": \"descendants\"}\n",
" ],\n",
" orientation=\"h\",\n",
").show()"
]
Expand All @@ -203,7 +209,7 @@
"metadata": {},
"outputs": [],
"source": [
"selector = {\"type\": \"descendants\", \"node\": \"geringfügig_beschäftigt\"}\n",
"selector = {\"type\": \"descendants\", \"node\": \"einkommensgrenzen__geringfügig_beschäftigt\"}\n",
"plot_dag(\n",
" environment=environment, show_labels=False, selectors=selector, orientation=\"h\"\n",
").show()"
Expand Down Expand Up @@ -234,7 +240,9 @@
"source": [
"plot_dag(\n",
" environment=environment,\n",
" selectors=[{\"node\": \"zu_verst_kapitaleink_y_sn\", \"type\": \"neighbors\"}],\n",
" selectors=[\n",
" {\"node\": \"abgeltungssteuer__kapitaleinkommen_y_sn\", \"type\": \"neighbors\"}\n",
" ],\n",
" orientation=\"h\",\n",
" hover_source_code=True,\n",
").show()"
Expand Down Expand Up @@ -281,7 +289,7 @@
"metadata": {},
"outputs": [],
"source": [
"selectors = [\"kapitaleink_brutto_y_sn\", \"zu_verst_kapitaleink_y_sn\"]\n",
"selectors = [\"kapitaleink_brutto_y_sn\", \"abgeltungssteuer__kapitaleinkommen_y_sn\"]\n",
"\n",
"plot_dag(environment=environment, selectors=selectors, orientation=\"h\").show()"
]
Expand All @@ -303,7 +311,7 @@
"source": [
"selector = {\n",
" \"type\": \"nodes\",\n",
" \"node\": [\"kapitaleink_brutto_y_sn\", \"zu_verst_kapitaleink_y_sn\"],\n",
" \"node\": [\"kapitaleink_brutto_y_sn\", \"abgeltungssteuer__kapitaleinkommen_y_sn\"],\n",
" \"select\": True, # optional\n",
"}"
]
Expand Down Expand Up @@ -333,9 +341,9 @@
"- If no selectors are provided, de-selectors de-select nodes from the complete DAG.\n",
"- Selection and de-selection works for all selector types which follow.\n",
"\n",
"For a simple and silly example, we want to reproduce the graph with the single node for `kapitaleink_brutto_y_sn` after, but starting from the last plot which also showed `zu_verst_kapitaleink_y_sn`.\n",
"For a simple and silly example, we want to reproduce the graph with the single node for `kapitaleink_brutto_y_sn` after, but starting from the last plot which also showed `abgeltungssteuer__kapitaleinkommen_y_sn`.\n",
"\n",
"First, we define the selectors. The first selector or dictionary in the list selects the two nodes. Note that the `\"select\"` key is `True` by default. The second key in the de-selects `\"zu_verst_kapitaleink_y_sn\"`."
"First, we define the selectors. The first selector or dictionary in the list selects the two nodes. Note that the `\"select\"` key is `True` by default. The second key in the de-selects `\"abgeltungssteuer__kapitaleinkommen_y_sn\"`."
]
},
{
Expand All @@ -348,11 +356,11 @@
"selectors = [\n",
" {\n",
" \"type\": \"nodes\",\n",
" \"node\": [\"kapitaleink_brutto_y_sn\", \"zu_verst_kapitaleink_y_sn\"],\n",
" \"node\": [\"kapitaleink_brutto_y_sn\", \"abgeltungssteuer__kapitaleinkommen_y_sn\"],\n",
" },\n",
" {\n",
" \"type\": \"nodes\",\n",
" \"node\": \"zu_verst_kapitaleink_y_sn\",\n",
" \"node\": \"abgeltungssteuer__kapitaleinkommen_y_sn\",\n",
" \"select\": False,\n",
" },\n",
"]\n",
Expand All @@ -366,7 +374,7 @@
"source": [
"### Ancestors and Descendants\n",
"\n",
"Two other types of selectors allow you to pick one node and all nodes which appear before or after this node. We call the nodes ancestors or descendants, respectively. To select `\"zu_verst_kapitaleink_y_sn\"` which is the calculated taxable capital income per Steuernummer and all its ancestors, do the following."
"Two other types of selectors allow you to pick one node and all nodes which appear before or after this node. We call the nodes ancestors or descendants, respectively. To select `\"abgeltungssteuer__kapitaleinkommen_y_sn\"` which is the calculated taxable capital income per Steuernummer and all its ancestors, do the following."
]
},
{
Expand All @@ -376,7 +384,7 @@
"metadata": {},
"outputs": [],
"source": [
"selector = {\"type\": \"ancestors\", \"node\": \"zu_verst_kapitaleink_y_sn\"}\n",
"selector = {\"type\": \"ancestors\", \"node\": \"abgeltungssteuer__kapitaleinkommen_y_sn\"}\n",
"plot_dag(environment=environment, selectors=selector, orientation=\"h\").show()"
]
},
Expand All @@ -385,7 +393,7 @@
"id": "33",
"metadata": {},
"source": [
"To see the variables which are explicitly and implicitly dependent on the information in `\"geringfügig_beschäftigt\"` use the type `\"descendants\"`."
"To see the variables which are explicitly and implicitly dependent on the information in `\"einkommensgrenzen__geringfügig_beschäftigt\"` use the type `\"descendants\"`."
]
},
{
Expand All @@ -395,7 +403,7 @@
"metadata": {},
"outputs": [],
"source": [
"selector = {\"type\": \"descendants\", \"node\": \"geringfügig_beschäftigt\"}\n",
"selector = {\"type\": \"descendants\", \"node\": \"einkommensgrenzen__geringfügig_beschäftigt\"}\n",
"plot_dag(environment=environment, selectors=selector, orientation=\"h\").show()"
]
},
Expand Down
22 changes: 17 additions & 5 deletions docs/tutorials/advanced_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,19 @@
"df = compute_taxes_and_transfers(\n",
" data=data,\n",
" environment=environment,\n",
" targets=[\"eink_st_y_sn\", \"bruttolohn_y_hh\", \"kindergeld_y_hh\"],\n",
" targets=[\n",
" \"taxes__einkommensteuer__betrag_y_sn\",\n",
" \"bruttolohn_y_hh\",\n",
" \"kindergeld_y_hh\",\n",
" ],\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we aggregate `eink_st_y_sn` to the household level and drop unused variables as\n",
"Next, we aggregate `taxes__einkommensteuer__betrag_y_sn` to the household level and drop unused variables as\n",
"well as duplicates from our DataFrame. The final DataFrame contains the yearly gross\n",
"income, income tax, child benefit, and number of children in the household."
]
Expand All @@ -372,7 +376,9 @@
"source": [
"# Aggregate eink_st_y_hh on the household level.\n",
"df = df.join(data[\"hh_id\"])\n",
"df[\"eink_st_y_hh\"] = df.groupby(\"hh_id\")[\"eink_st_y_sn\"].transform(\"sum\")\n",
"df[\"eink_st_y_hh\"] = df.groupby(\"hh_id\")[\n",
" \"taxes__einkommensteuer__betrag_y_sn\"\n",
"].transform(\"sum\")\n",
"# Select variables of interest for further steps.\n",
"df = df[[\"bruttolohn_y_hh\", \"eink_st_y_hh\", \"kindergeld_y_hh\"]].drop_duplicates()\n",
"df.head().round(2)"
Expand Down Expand Up @@ -448,7 +454,11 @@
"outputs = compute_taxes_and_transfers(\n",
" data=new_data,\n",
" environment=environment,\n",
" targets=[\"kindergeld_y_hh\", \"eink_st_y_sn\", \"bruttolohn_y_hh\"],\n",
" targets=[\n",
" \"kindergeld_y_hh\",\n",
" \"taxes__einkommensteuer__betrag_y_sn\",\n",
" \"bruttolohn_y_hh\",\n",
" ],\n",
")"
]
},
Expand All @@ -460,7 +470,9 @@
"source": [
"# Aggregate eink_st_y_hh on the household level.\n",
"outputs = outputs.join(new_data[\"hh_id\"])\n",
"outputs[\"eink_st_y_hh\"] = outputs.groupby(\"hh_id\")[\"eink_st_y_sn\"].transform(\"sum\")\n",
"outputs[\"eink_st_y_hh\"] = outputs.groupby(\"hh_id\")[\n",
" \"taxes__einkommensteuer__betrag_y_sn\"\n",
"].transform(\"sum\")\n",
"\n",
"df_new = outputs.set_index(new_data.hh_id)\n",
"df_new = df_new[\n",
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/basic_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@
"source": [
"# Create list of target variables.\n",
"targets = [\n",
" \"ges_krankenv_beitr_arbeitnehmer_m\",\n",
" \"ges_rentenv_beitr_arbeitnehmer_m\",\n",
" \"arbeitsl_v_beitr_arbeitnehmer_m\",\n",
" \"ges_pflegev_beitr_arbeitnehmer_m\",\n",
" \"sozialversicherungsbeitraege__krankenversicherung__betrag_arbeitnehmer_m\",\n",
" \"sozialversicherungsbeitraege__rentenversicherung__betrag_arbeitnehmer_m\",\n",
" \"sozialversicherungsbeitraege__arbeitslosenversicherung__betrag_arbeitnehmer_m\",\n",
" \"sozialversicherungsbeitraege__pflegeversicherung__betrag_m\",\n",
"]"
]
},
Expand Down
Loading
Loading