refactor: add typing to & do maintenance of periods#1223
refactor: add typing to & do maintenance of periods#1223bonjourmauko merged 20 commits intomasterfrom
Conversation
3601736 to
9317b7f
Compare
9317b7f to
eb159e8
Compare
d2659c6 to
b27db7c
Compare
benjello
left a comment
There was a problem hiding this comment.
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
eternityinstants 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))>infis a float, periods andinstants are integers. Mixed data types make memory optimisations impossible.
inf, you should update it to check for-1or use theis_eternalmethod.periods.instantno longer returnsNoneperiods.InstantErrorNew features
Instant.eternity()Instant.is_eternalandPeriod.is_eternalbool).periods.instantparses also ISO calendar strings (weeks)2022-W01is now a valid inputTechnical changes
pendulum