-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add method for propagating units to descendants for `ParameterS…
…cale` objects
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
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
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
68 changes: 68 additions & 0 deletions
68
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,68 @@ | ||
description: Propagate units in metadata of a scaled parameter to its descendants | ||
metadata: | ||
type: single_amount | ||
threshold_unit: child | ||
amount_unit: currency-USD | ||
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: | ||
a: b | ||
- 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,14 @@ | ||
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"] == "currency-USD" |