-
Notifications
You must be signed in to change notification settings - Fork 76
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
refactor: add typing to & do maintenance of periods #1223
Conversation
3601736
to
9317b7f
Compare
9317b7f
to
eb159e8
Compare
d2659c6
to
b27db7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an empty file openfisca_core/periods/py.typed
You should check these changes against openfisca-france
and openfisca-survey-manager
since it may surface some problems that should be documented in the changelog to ease transition and to diagnose the right version bump.
Method `periods.instant` had way too much branching and cyclomatic complexity. It has been refactored so to make use of `functools.singledispatch` to improve readability and testing. BREAKING CHANGE: `periods.instant` no longer returns `None`. Now, it raises `periods.InstantError` instead.
Broaden the expected argument type to be of generic type `object`, and do an explicit casting to help users know that the expected argument for that function is a string.
Previously, eternal periods and entities were populated with `inf` values, which are floats. This was an exception, already, as the rest of the values are integers. If you store, for example, thousands of instants in a numpy array, just one eternal instant will force the whole array to pass from integer to float. Now, eternal instants are populated with `-1`, and can be produced with `Instant.eternity()` and `Period.eternity()`. Also, they can be checked with `is_eternal`.
That is pure documentation. Is to let others know the code is typed. See: https://peps.python.org/pep-0561/
OK. |
It all works @benjello :) In France, the only check that fails is the Conda build, but that is because we're testing against a URL and not a PyPi release, which is normal, as this has yet to be merged and released. The important is that the tests pass. |
LGTM? |
Depends on openfisca/openfisca-core#1223 * Minor change. - Update OpenFisca-Core to 42.0.0
Fixes #917
Fixes #1229
Fixes #1232
Depends on #1220
Depended upon by #1146
Breaking changes
eternity
instants and periods<Instant(-1, -1, -1)>
instead of<Instant(inf, inf, inf)>
<Period(('eternity', <Instant(-1, -1, -1)>, -1))>
instead of
<Period(('eternity', <Instant(inf, inf, inf)>, inf))>
inf
is a float, periods andinstants are integers. Mixed data types make memory optimisations impossible.
inf
, you should update it to check for-1
or use theis_eternal
method.periods.instant
no longer returnsNone
periods.InstantError
New features
Instant.eternity()
Instant.is_eternal
andPeriod.is_eternal
bool
).periods.instant
parses also ISO calendar strings (weeks)2022-W01
is now a valid inputTechnical changes
pendulum