-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method for propagating units to descendants for
ParameterScale
…
…objects (#162) * feat: add method for propagating units to descendants for `ParameterScale` objects * feat: increase test coverage * chore: add changelog * feat: increase test coverage * fix: update sphinx version * fix: change style to reduce nested ifs.
- Loading branch information
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,4 @@ | ||
- bump: minor | ||
changes: | ||
changed: | ||
- Add method for propagating units to descendants for ParameterScale objects |
This file contains 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 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 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
69 changes: 69 additions & 0 deletions
69
tests/core/parameter_validation/parameter_for_unit_propagation.yaml
This file contains 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,69 @@ | ||
description: Propagate units in metadata of a scaled parameter to its descendants | ||
metadata: | ||
type: single_amount | ||
threshold_unit: child | ||
amount_unit: currency-USD | ||
rate_unit: /1 | ||
label: Test unit propagation | ||
|
||
brackets: | ||
- threshold: | ||
values: | ||
1995-01-01: 0 | ||
amount: | ||
values: | ||
2017-01-01: 8_340 | ||
2018-01-01: 8_510 | ||
2019-01-01: 8_650 | ||
2020-01-01: 8_790 | ||
2021-01-01: 11_610 | ||
2022-01-01: 9_160 | ||
2023-01-01: 9_800 | ||
2024-01-01: 10_330 | ||
- threshold: | ||
values: | ||
1995-01-01: 1 | ||
amount: | ||
values: | ||
2017-01-01: 18_340 | ||
2018-01-01: 18_700 | ||
2019-01-01: 19_030 | ||
2020-01-01: 19_330 | ||
2021-01-01: 19_520 | ||
2022-01-01: 20_130 | ||
2023-01-01: 21_560 | ||
2024-01-01: 22_720 | ||
metadata: | ||
unit: US dollars | ||
- threshold: | ||
values: | ||
1995-01-01: 2 | ||
metadata: | ||
a: b | ||
amount: | ||
values: | ||
2017-01-01: 18_340 | ||
2018-01-01: 18_700 | ||
2019-01-01: 19_030 | ||
2020-01-01: 19_330 | ||
2021-01-01: 19_520 | ||
2022-01-01: 20_130 | ||
2023-01-01: 21_560 | ||
2024-01-01: 22_720 | ||
- threshold: | ||
values: | ||
1995-01-01: 3 | ||
metadata: | ||
a: b | ||
amount: | ||
values: | ||
2017-01-01: 18_340 | ||
2018-01-01: 18_700 | ||
2019-01-01: 19_030 | ||
2020-01-01: 19_330 | ||
2021-01-01: 19_520 | ||
2022-01-01: 20_130 | ||
2023-01-01: 21_560 | ||
2024-01-01: 22_720 | ||
metadata: | ||
a: b |
This file contains 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,16 @@ | ||
import os | ||
|
||
from policyengine_core.parameters import load_parameter_file | ||
|
||
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
def test_propagate_units(): | ||
path = os.path.join(BASE_DIR, "parameter_for_unit_propagation.yaml") | ||
parameter = load_parameter_file(path) | ||
parameter.propagate_units() | ||
for i in range(4): | ||
assert parameter.brackets[i].threshold.metadata["unit"] == "child" | ||
assert parameter.brackets[i].amount.metadata["unit"] == ( | ||
"US dollars" if i == 1 else "currency-USD" | ||
) |