-
Notifications
You must be signed in to change notification settings - Fork 82
Allow array parameters #982
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
Changes from 7 commits
d363c82
315e2c6
ec93ac8
4b36f6f
8a23aae
9d8f6ce
4e66961
4faafff
77d5808
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import os | ||
| import sys | ||
| import traceback | ||
| import typing | ||
MattiSG marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import yaml | ||
| import numpy as np | ||
|
|
@@ -36,7 +37,7 @@ | |
| # 'unit' and 'reference' are only listed here for backward compatibility. | ||
| # It is now recommended to include them in metadata, until a common consensus emerges. | ||
| COMMON_KEYS = {'description', 'metadata', 'unit', 'reference', 'documentation'} | ||
| ALLOWED_PARAM_TYPES = (float, int, bool, type(None)) | ||
| ALLOWED_PARAM_TYPES = (float, int, bool, type(None), typing.List) | ||
|
||
|
|
||
|
|
||
| def date_constructor(loader, node): | ||
|
|
@@ -319,7 +320,7 @@ def validate(self, data): | |
| ) | ||
| if not isinstance(value, ALLOWED_PARAM_TYPES): | ||
| raise ParameterParsingError( | ||
| "Invalid value in {} : {}".format(self.name, value), | ||
| "Value in {} has type {}, which is not one of the allowed types ({}): {}".format(self.name, type(value), ALLOWED_PARAM_TYPES, value), | ||
| self.file_path | ||
| ) | ||
|
|
||
|
|
@@ -851,7 +852,7 @@ def load_parameter_file(file_path, name = ''): | |
| :returns: An instance of :any:`ParameterNode` or :any:`Scale` or :any:`Parameter`. | ||
| """ | ||
| if not os.path.exists(file_path): | ||
| raise ValueError("{} doest not exist".format(file_path)) | ||
| raise ValueError("{} does not exist".format(file_path)) | ||
MattiSG marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if os.path.isdir(file_path): | ||
| return ParameterNode(name, directory_path = file_path) | ||
| data = _load_yaml_file(file_path) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ | |
|
|
||
| setup( | ||
| name = 'OpenFisca-Core', | ||
| version = '35.1.1', | ||
| version = '35.2.0', | ||
| author = 'OpenFisca Team', | ||
| author_email = '[email protected]', | ||
| classifiers = [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| description: Array types should be allowed. | ||
| values: | ||
| 2013-01-01: | ||
| value: [ FR ] | ||
| 2018-06-01: | ||
| value: [ ES, FR, IT, NZ ] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |||||
| year = 2016 | ||||||
|
|
||||||
|
|
||||||
| def check(file_name, keywords): | ||||||
| def check_fails_with_message(file_name, keywords): | ||||||
| path = os.path.join(BASE_DIR, file_name) + '.yaml' | ||||||
| try: | ||||||
| load_parameter_file(path, file_name) | ||||||
|
|
@@ -22,7 +22,7 @@ def check(file_name, keywords): | |||||
| @pytest.mark.parametrize("test", [ | ||||||
| ('indentation', {'Invalid YAML', 'indentation.yaml', 'line 2', 'mapping values are not allowed'}), | ||||||
| ('wrong_scale', {'Unexpected property', 'scale[1]', 'treshold'}), | ||||||
| ('wrong_value', {'Invalid value', 'wrong_value[2015-12-01]', '1A'}), | ||||||
| ('wrong_value', {'not one of the allowed types', 'wrong_value[2015-12-01]', '1A'}), | ||||||
| ('unexpected_key_in_parameter', {'Unexpected property', 'unexpected_key'}), | ||||||
| ('wrong_type_in_parameter', {'must be of type object'}), | ||||||
| ('wrong_type_in_value_history', {'must be of type object'}), | ||||||
|
|
@@ -37,7 +37,12 @@ def check(file_name, keywords): | |||||
| ]) | ||||||
| def test_parsing_errors(test): | ||||||
| with pytest.raises(ParameterParsingError): | ||||||
| check(*test) | ||||||
| check_fails_with_message(*test) | ||||||
|
|
||||||
|
|
||||||
| def test_array_type(): | ||||||
| path = os.path.join(BASE_DIR, 'array_type.yaml') | ||||||
| load_parameter_file(path, 'array_type') | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will anyway pass as it is a truthy value -otherwise it would fail. Just a proposition for reader's clarity. |
||||||
|
|
||||||
|
|
||||||
| def test_filesystem_hierarchy(): | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.