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

add the possibility to load the parameter value of a previous year. #306

Merged
merged 7 commits into from Nov 12, 2021

Conversation

ChristianZimpelmann
Copy link
Member

@ChristianZimpelmann ChristianZimpelmann commented Nov 8, 2021

Closes #305

Add the possibility to load the value of a parameter of the previous year when calling set_up_policy_environment

@codecov
Copy link

codecov bot commented Nov 8, 2021

Codecov Report

Merging #306 (204b400) into grundrente (9fb1411) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff               @@
##           grundrente     #306      +/-   ##
==============================================
+ Coverage       92.74%   92.81%   +0.07%     
==============================================
  Files              70       71       +1     
  Lines            2783     2811      +28     
==============================================
+ Hits             2581     2609      +28     
  Misses            202      202              
Impacted Files Coverage Δ
gettsim/policy_environment.py 100.00% <100.00%> (ø)
gettsim/tests/test_policy_environment.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9fb1411...204b400. Read the comment docs.

Copy link
Collaborator

@Eric-Sommer Eric-Sommer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ChristianZimpelmann . I think your approach works for the grundrente case. I wonder however, whether we'd rather want to have a generic solution for every parameter. Right now, access_different_date needs to be specified for the parameter. Why not rather create a different set of parameters by invoking set_up_policy_environment() with a different year?

# Also load earlier parameter values if this is specified in yaml
if "access_different_date" in raw_group_data[param]:
if raw_group_data[param]["access_different_date"] == "vorjahr":
date_last_year = date - datetime.timedelta(days=365)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not robust to leap years, isn't it? I'd suggest something like

date_last_year = date(date.year - 1, date.month, date.day)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will adjust. But I think your solution also needs to take care of leap years in case the current date is Februar 29th

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

# from gettsim import compute_taxes_and_transfers
# from gettsim import set_up_policy_environment
# from gettsim.synthetic_data.synthetic import create_synthetic_data
# def test_synthetic():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test should be reactivated before merging

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR will be merged to the grundrente PR. I will definitelly reactivate it before merging to main branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test should run through now

@hmgaudecker
Copy link
Collaborator

Thanks @ChristianZimpelmann . I think your approach works for the grundrente case. I wonder however, whether we'd rather want to have a generic solution for every parameter. Right now, access_different_date needs to be specified for the parameter. Why not rather create a different set of parameters by invoking set_up_policy_environment() with a different year?

This wholly depends on how often we are likely to need it. Invoking the whole beast is costly every time 'round.

Do (m)any other instances come to mind where we'd need the parameters of the previous year? In most cases, it seems to me like a question of individual data... (e.g., ALG I benefits and the like).

Thoughts, @Eric-Sommer @mjbloemer ?

@ChristianZimpelmann
Copy link
Member Author

ChristianZimpelmann commented Nov 10, 2021

Thank you for your comments, Eric!

Why not rather create a different set of parameters by invoking set_up_policy_environment() with a different year?

I think we should hide this functionality from the user. Therefore, we shouldn't require them to regularly call set_up_policy_environment twice or with two dates.

Conversely, calling set_up_policy_environment for a given date should return a dict of all parameters that are necessary to run gettsim for this particular date (including parameters from the earlier year if necessary).

The two alternatives I was thinking about were:

  • adding parameters of last year if specified in .yaml (this is currently implemented)
  • adding parameters of last year for all parameters by default

Since we will only need this for a small subset of parameters, I decided for the first solution.

Copy link
Collaborator

@Eric-Sommer Eric-Sommer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, you convinced me 😄

@ChristianZimpelmann
Copy link
Member Author

Thank you very much, @Eric-Sommer 😄

@ChristianZimpelmann ChristianZimpelmann merged commit 7cd0aee into grundrente Nov 12, 2021
@ChristianZimpelmann ChristianZimpelmann deleted the para_last_year branch November 12, 2021 07:08
@ChristianZimpelmann ChristianZimpelmann mentioned this pull request Feb 18, 2022
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants