-
Notifications
You must be signed in to change notification settings - Fork 75
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
Switch parameters to YAML #552
Conversation
Still to do :
|
openfisca_core/reforms.py
Outdated
Copy the baseline TaxBenefitSystem legislation_json attribute and return it. | ||
Used by reforms which need to modify the legislation_json, usually in the build_reform() function. | ||
Validates the new legislation. | ||
Used by reforms which need to modify the legislation parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use if the reform asks for legislation parameter modification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified
openfisca_core/reforms.py
Outdated
class Reform(TaxBenefitSystem): | ||
"""A modified TaxBenefitSystem | ||
|
||
A reformed TaxBenefitSystem must subclass `Reform` and implement a method `apply()`. Such a function can add or replace variables and call `self.modify_legislation()` to modify the parameters of the legislation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In OpenFisca, a reform is a modified TaxBenefitSystem.
It can add or replace variables and call self.modify_legislation()to modify the parameters of the legislation. All reforms must subclass
Reformand implement a
apply()` method .
openfisca_core/taxbenefitsystems.py
Outdated
@@ -48,10 +55,10 @@ class VariableNameConflict(Exception): | |||
|
|||
class TaxBenefitSystem(object): | |||
""" | |||
Represents the legislation. | |||
Represents the legislation. It stores parameters (values defined for everyone) and variables (values defined for some given entity e.g. a person). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'enlèverait "Represents the legislation" --> cela reste déroutant, quand legislation peut représenter seulement les paramètres dans certain contextes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est plutôt dans l'autre sens qu'il faudrait aller: le TBS représente la législation, mais les paramètres sont... des paramètres.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, je ne change rien
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not check the code deeply, but here is my first review.
The main thing that puzzles me is the type
attribute. This was not mentioned in the issue discussions, and I find it a little heavy (espacially the almost empty files that need to be put in each intermediate directory)
CHANGELOG.md
Outdated
|
||
Now: | ||
```yaml | ||
type: node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that necessary ?
Can't we figure out if it's a nose just by checking its properties ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
CHANGELOG.md
Outdated
descrption: Taux d'impôt sur les salaires | ||
unit: /1 | ||
values: | ||
'2016-01-01': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the quotes necessary ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
CHANGELOG.md
Outdated
type: node | ||
taux: | ||
type: parameter | ||
descrption: Taux d'impôt sur les salaires |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
CHANGELOG.md
Outdated
impot: | ||
type: node | ||
taux: | ||
type: parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that necessary ?
Can't we figure out if it's a nose just by checking its properties ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
CHANGELOG.md
Outdated
|
||
- The XML attributes `format` and `type` are replaced by the YAML attribute `unit` than can take as values `year`, `currency` and `/1`. | ||
|
||
* Refactor the internal representation and the interface of legislation parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the "Breaking changes" part, as a user, I want to check if something that I was using has been removed/changed.
Reading this part doesn't help me much. I know something has been refactored (by that's not really my business), and I know that new classes have been introduced. But what former classes/methods/functions/attributes have been removed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to another section
CHANGELOG.md
Outdated
#### Technical changes | ||
|
||
* The variables `*legislation_json*` are replaced by `*legislation*` because the format json is no longer used. | ||
* The expression "compact legislation" is replaced by the expression "legislation at instant". For example, `taxbenefitsystem.compact_legislation_by_instant_cache` is renamed as `taxbenefitsystem.legislation_at_instant_cache`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that a breaking change ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I clarified it a bit
openfisca_core/simulations.py
Outdated
debug = False | ||
debug_all = False # When False, log only formula calls with non-default parameters. | ||
period = None | ||
baseline_compact_legislation_by_instant_cache = None | ||
baseline_legislation_at_instant_cache = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaking change must be documented in the changelog.
Maybe we should also make this attribute private ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes !
openfisca_core/simulations.py
Outdated
@@ -11,11 +11,11 @@ | |||
|
|||
|
|||
class Simulation(object): | |||
compact_legislation_by_instant_cache = None | |||
legislation_at_instant_cache = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaking change must be documented in the changelog.
Maybe we should also make this attribute private ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes !
openfisca_core/taxbenefitsystems.py
Outdated
@@ -48,10 +55,10 @@ class VariableNameConflict(Exception): | |||
|
|||
class TaxBenefitSystem(object): | |||
""" | |||
Represents the legislation. | |||
Represents the legislation. It stores parameters (values defined for everyone) and variables (values defined for some given entity e.g. a person). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est plutôt dans l'autre sens qu'il faudrait aller: le TBS représente la législation, mais les paramètres sont... des paramètres.
openfisca_core/taxbenefitsystems.py
Outdated
# TODO: Currently: Don't use a weakref, because they are cleared by Paste (at least) at each call. | ||
self.compact_legislation_by_instant_cache = {} # weakref.WeakValueDictionary() | ||
self.legislation_at_instant_cache = {} # weakref.WeakValueDictionary() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are renaming it, should we be opportunistic and rename it to parameters_at_instant_cache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
Ok to postpone, but that is quite important to get back.
Ok to postpone.
This is used only in one reform at the moment, but the economical logic behind it is not unique. In this case, replace the
It seems to be the Web API, which cannot serve the If regaining the We just need to obtain the list of currently exposed
@benjello is this ok with you? It does seem more readable to me to have |
@MattiSG : the trade-off for me is choosing the less puzzling ambiguity:
I do not have a clear preference ;-) so it is ok change legislation in parameters |
Thanks for your reviews. I'm not sure about how the caching of the parameters should be tested. |
For caching:
The current options seem to be:
In which case, I favour optional validation and recommendation to install |
CHANGELOG.md
Outdated
value: 0.3 | ||
``` | ||
|
||
- The XML attributes `format` and `type` are replaced by the YAML attribute `unit` than can take as values `year`, `currency` and `/1`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it a free text field for now.
CHANGELOG.md
Outdated
``` | ||
- Now: | ||
```python | ||
parameters.impot_revenu.bareme[1].threshold.update(period=reform_period, value=6011) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around =
CHANGELOG.md
Outdated
from openfisca_core.parameters import ParameterNode | ||
|
||
inflation = .001 | ||
reform_parameters_subtree = Node('plf2016_conterfactual', validated_yaml = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParameterNode
CHANGELOG.md
Outdated
|
||
- This way of creating parameters is deprecated (see below), except when using dynamically computed values. It is the case in the example because `round(1135 * (1 + inflation))` is computed at run time. | ||
|
||
* The function `reforms.compose_reforms()` is removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove function reforms.compose_reforms()
openfisca_core/parameters.py
Outdated
self.values_list = values_list | ||
|
||
def __repr__(self): | ||
return 'ValuesHistory "{}"\n'.format(self.name) + ''.join(' {}: {}\n'.format(value.instant_str, value.value) for value in self.values_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use os.linesep
openfisca_core/reforms.py
Outdated
i += 1 | ||
|
||
return new_items | ||
assert isinstance(reform_parameters, ParameterNode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. If this is false, there will be no exploitable error message. Don't use assertions.
openfisca_core/simulations.py
Outdated
return self._get_baseline_parameters_at_instant(instant) | ||
return self._get_parameters_at_instant(instant) | ||
|
||
def legislation_at(self, instant, use_baseline = False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this retro-compatibility layer is really necessary
openfisca_core/taxbenefitsystems.py
Outdated
|
||
self.parameters = parameters | ||
|
||
def get_parameters(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think parameters
is clean enough so that we can expose it directly
openfisca_core/taxbenefitsystems.py
Outdated
""" | ||
return self.parameters | ||
|
||
def get_legislation(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this retro-compatibility layer really necessary ?
path_fragments = path_fragments + [child_name], | ||
) | ||
for child_name, child in children.items(): | ||
child_type = type(child).__name__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import the types instead of using the names
ea25cca
to
fd63109
Compare
Connected to #523
See changelog (TODO: copy the changelog here after merge)