-
Notifications
You must be signed in to change notification settings - Fork 84
Re-add support for dispatch/divide by days #1143
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
31a7460
Add test to dispatch by month
bonjourmauko 3e302e8
Add general test to dispatch
bonjourmauko 3467deb
Add tests to set divide by period
bonjourmauko e7f3a0d
Add days to set input dispatch/divide
bonjourmauko 8644ef9
Version & CHANGELOG bump
bonjourmauko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import pytest | ||
|
|
||
| from openfisca_core import holders, periods, tools | ||
| from openfisca_core.entities import Entity | ||
| from openfisca_core.holders import Holder | ||
| from openfisca_core.periods import Instant, Period | ||
| from openfisca_core.populations import Population | ||
| from openfisca_core.variables import Variable | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def people(): | ||
| return Entity( | ||
| key = "person", | ||
| plural = "people", | ||
| label = "An individual member of a larger group.", | ||
| doc = "People have the particularity of not being someone else.", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def Income(people): | ||
| return type( | ||
| "Income", | ||
| (Variable,), { | ||
| "value_type": float, | ||
| "entity": people | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def population(people): | ||
| population = Population(people) | ||
| population.count = 1 | ||
| return population | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("dispatch_unit, definition_unit, values, expected", [ | ||
| [periods.YEAR, periods.YEAR, [1.], [3.]], | ||
| [periods.YEAR, periods.MONTH, [1.], [36.]], | ||
| [periods.YEAR, periods.DAY, [1.], [1096.]], | ||
| [periods.MONTH, periods.YEAR, [1.], [1.]], | ||
| [periods.MONTH, periods.MONTH, [1.], [3.]], | ||
| [periods.MONTH, periods.DAY, [1.], [90.]], | ||
| [periods.DAY, periods.YEAR, [1.], [1.]], | ||
| [periods.DAY, periods.MONTH, [1.], [1.]], | ||
| [periods.DAY, periods.DAY, [1.], [3.]], | ||
| ]) | ||
| def test_set_input_dispatch_by_period( | ||
| Income, | ||
| population, | ||
| dispatch_unit, | ||
| definition_unit, | ||
| values, | ||
| expected, | ||
| ): | ||
| Income.definition_period = definition_unit | ||
| income = Income() | ||
| holder = Holder(income, population) | ||
| instant = Instant((2022, 1, 1)) | ||
| dispatch_period = Period((dispatch_unit, instant, 3)) | ||
|
|
||
| holders.set_input_dispatch_by_period(holder, dispatch_period, values) | ||
| total = sum(map(holder.get_array, holder.get_known_periods())) | ||
|
|
||
| tools.assert_near(total, expected, absolute_error_margin = 0.001) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("divide_unit, definition_unit, values, expected", [ | ||
| [periods.YEAR, periods.YEAR, [3.], [1.]], | ||
| [periods.YEAR, periods.MONTH, [36.], [1.]], | ||
| [periods.YEAR, periods.DAY, [1095.], [1.]], | ||
| [periods.MONTH, periods.YEAR, [1.], [1.]], | ||
| [periods.MONTH, periods.MONTH, [3.], [1.]], | ||
| [periods.MONTH, periods.DAY, [90.], [1.]], | ||
| [periods.DAY, periods.YEAR, [1.], [1.]], | ||
| [periods.DAY, periods.MONTH, [1.], [1.]], | ||
| [periods.DAY, periods.DAY, [3.], [1.]], | ||
| ]) | ||
| def test_set_input_divide_by_period( | ||
| Income, | ||
| population, | ||
| divide_unit, | ||
| definition_unit, | ||
| values, | ||
| expected, | ||
| ): | ||
| Income.definition_period = definition_unit | ||
| income = Income() | ||
| holder = Holder(income, population) | ||
| instant = Instant((2022, 1, 1)) | ||
| divide_period = Period((divide_unit, instant, 3)) | ||
|
|
||
| holders.set_input_divide_by_period(holder, divide_period, values) | ||
| last = holder.get_array(holder.get_known_periods()[-1]) | ||
|
|
||
| tools.assert_near(last, expected, absolute_error_margin = 0.001) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ | |
|
|
||
| setup( | ||
| name = 'OpenFisca-Core', | ||
| version = '35.10.0', | ||
| version = '35.10.1', | ||
| author = 'OpenFisca Team', | ||
| author_email = '[email protected]', | ||
| classifiers = [ | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.