iza-institute-of-labor-economics / gettsim

The GErman Taxes and Transfers SIMulator
https://gettsim.readthedocs.io/
GNU Affero General Public License v3.0
54 stars 32 forks source link

BUG: Ignore FunctionsAndColumnsOverlapWarning when calling GETTSIM via pytask #716

Closed MImmesberger closed 6 months ago

MImmesberger commented 6 months ago

Bug description

In my script, I call GETTSIM inside a function (which is called via pytask if that matters). Since I'm overwriting some columns, I get a FunctionsAndColumnsOverlapWarning.

Now turning this warning off works only if I add warnings.filterwarnings("ignore", category=FunctionsAndColumnsOverlapWarning) to the function body. It does not work when I put the warnings setting at the top of my script (as suggested by the warning message).

I'm not sure whether this behavior is intended. Just wanted to report it, in case it isn't.

Code example

This produces a warning ```python import warnings from gettsim import ( compute_taxes_and_transfers, create_synthetic_data, set_up_policy_environment, FunctionsAndColumnsOverlapWarning ) from pytask import task from pathlib import Path warnings.filterwarnings("ignore", category=FunctionsAndColumnsOverlapWarning) @task def task_test( produces = Path("output/test.pickle") ): params, funcs = set_up_policy_environment(2023) target = "ges_rente_vorauss_besond_langj" data = create_synthetic_data( n_adults = 2, n_children = 0, ) data["ges_rente_wartezeit_45"] = True results = compute_taxes_and_transfers( data = data, params = params, functions = funcs, targets = target, ) results.to_pickle(produces) ```
This doesn't produce a warning ```python import warnings from gettsim import ( compute_taxes_and_transfers, create_synthetic_data, set_up_policy_environment, FunctionsAndColumnsOverlapWarning ) from pytask import task from pathlib import Path @task def task_test( produces = Path("output/test.pickle") ): warnings.filterwarnings("ignore", category=FunctionsAndColumnsOverlapWarning) params, funcs = set_up_policy_environment(2023) target = "ges_rente_vorauss_besond_langj" data = create_synthetic_data( n_adults = 2, n_children = 0, ) data["ges_rente_wartezeit_45"] = True results = compute_taxes_and_transfers( data = data, params = params, functions = funcs, targets = target, ) results.to_pickle(produces) ```
MImmesberger commented 6 months ago

Actually, I think this is pytask-specific. Just tried to reproduce it in a Jupyter Notebook and in a script where I call the functions manually and there everything worked fine.

So we probably cannot do much from the GETTSIM side, right?

hmgaudecker commented 6 months ago

Does this help? https://pytask-dev.readthedocs.io/en/stable/how_to_guides/capture_warnings.html

MImmesberger commented 6 months ago

Thanks! Admittedly, I wasn't aware of this (even though there is a link in the warning, shame on me).

I didn't manage to silence the warning via

filterwarnings = [
    'ignore:Your data provides the columns:',
]

nor via

filterwarnings = [
    "ignore::FunctionsAndColumnsOverlapWarning",
]
MImmesberger commented 6 months ago

@timmens and I discovered that the correct syntax would be:

filterwarnings = [
    "ignore::gettsim.FunctionsAndColumnsOverlapWarning",
]

Corresponding issue for pytask's documentation is here.