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

Improve age computation formula and Variables tutorial comments #43

Merged
merged 9 commits into from
Jun 6, 2018

Conversation

MattiSG
Copy link
Member

@MattiSG MattiSG commented May 21, 2018

  • Tax and benefit system evolution.
  • Impacted periods: all.
  • Impacted areas: demographics.age
  • Details:
    • Improve reliability and accuracy of age formula
    • Improve variables comments

Comments improvements are only partly a knight: PRs such as ServiceInnovationLab/openfisca-aotearoa#15 show that reusers will copy and paste comments and that can lead to review friction.

@MattiSG MattiSG requested review from sandcha and fpagnoux May 21, 2018 06:11
@MattiSG
Copy link
Member Author

MattiSG commented May 21, 2018

@fpagnoux CircleCI's flake8 complaint seems a bit strange to me, since it is related to the age formula you wrote would you mind handling it? 🙂

./openfisca_country_template/variables/demographics.py:12:1: F401 'numpy.datetime64' imported but unused

@benjello
Copy link
Member

Surfing on this PR: @guillett @fpagnoux : should we transpose this to france ?

# This file defines the variables of our legislation.
# A variable is property of a person, or an entity (e.g. a household).
# This file defines variables for the modelled legislation.
# A variable is a property of an Entity such as a Person, a Family…
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use Household? There is no Family in this model.

from openfisca_country_template.entities import *

# Import additional NumPy helpers to work on specific data types
from numpy import datetime64
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we are actually using this import anymore, and that's why Flake is complaning.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but I wanted a double check from the person who wrote the initial code 😉

return (datetime64(period.date) - birth).astype('timedelta64[Y]')
birth_year = birth.astype('datetime64[Y]').astype(int) + 1970
birth_month = birth.astype('datetime64[M]').astype(int) % 12 + 1
birth_day = (birth - birth.astype('datetime64[M]') + 1).astype(int)
Copy link
Member

Choose a reason for hiding this comment

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

Frankly ugly, but we don't have better yet

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd really like that a time helper library is researched and vetted for.

Copy link
Member

Choose a reason for hiding this comment

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

We started to ask around, and there are candidates (Maya, Arrow, etc.). Though in this specific case, we need to handle vectors of dates, which will be a clear limitation.
If we were to use a library, we should also probably also use it to handle periods. So IMO this is related to openfisca/openfisca-core#670.

@fpagnoux
Copy link
Member

Surfing on this PR: @guillett @fpagnoux : should we transpose this to france ?

Probably a good idea, I think there was an issue opened about it somewhere.

@MattiSG MattiSG requested a review from fpagnoux May 28, 2018 00:40
@MattiSG MattiSG assigned MattiSG and fpagnoux and unassigned fpagnoux May 28, 2018
@MattiSG
Copy link
Member Author

MattiSG commented May 30, 2018

@fpagnoux the tests seem to show there is an issue with the formula 😕

We should probably add more tests to this in any case, including for leap years.

@fpagnoux
Copy link
Member

@fpagnoux the tests seem to show there is an issue with the formula 😕

Indeed. I fixed a formula and added a test for leap years. Feel free to add the tests you'll find relevant 🙂.

Copy link
Member

@fpagnoux fpagnoux left a comment

Choose a reason for hiding this comment

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

Seems mergeable to me. I agree that more tests would be a good thing though.

@MattiSG
Copy link
Member Author

MattiSG commented Jun 6, 2018

That was an annoying rebase, hopefully I got it right 😉

@MattiSG
Copy link
Member Author

MattiSG commented Jun 6, 2018

hopefully I got it right

(just kidding, I double-checked that the diff from the resulting rebase to the previous branch was equal to the changes made to master)

@MattiSG MattiSG merged commit 18606ee into master Jun 6, 2018
@MattiSG MattiSG deleted the age branch June 6, 2018 05:55
@bonjourmauko bonjourmauko added the policy:rfc Request for comments label Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
policy:rfc Request for comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants