Skip to content
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

Include bracket rates and thresholds in scale descendants #1113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 35.7.9 [#1113](https://github.com/openfisca/openfisca-core/pull/1113)

### Technical changes

- Fixed a bug where `get_descendants` would not return rates and thresholds from `ParameterScale`s.

### 35.7.8 [#1086](https://github.com/openfisca/openfisca-core/pull/1086)

#### Technical changes
Expand Down
9 changes: 8 additions & 1 deletion openfisca_core/parameters/parameter_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ def __repr__(self):
)

def get_descendants(self):
return iter(())
returned_any_results = False
for bracket in self.brackets:
for allowed_key_name in bracket._allowed_keys:
if hasattr(bracket, allowed_key_name):
yield getattr(bracket, allowed_key_name)
returned_any_results = True
if not returned_any_results:
return iter(())
Comment on lines +71 to +72
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example where this situation occurs? 🤔 It could be added as a test.


def clone(self):
clone = commons.empty_clone(self)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

setup(
name = 'OpenFisca-Core',
version = '35.7.8',
version = '35.7.9',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down
47 changes: 47 additions & 0 deletions tests/core/tax_scales/test_tax_scale_descendants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
def test_tax_scale_descendants_are_complete():
"""Tests that calling the `get_descendant` function of a ParameterScale returns the rates and thresholds as Parameters.
"""

from openfisca_core.parameters import ParameterNode, Parameter

parameters = ParameterNode("parameters", data={
"root_node": {
"first_child": {
"scale_parameter": {
"brackets": [
{
"rate": {
"2022-01-01": 0.1,
},
"threshold": {
"2022-01-01": 0,
}
},
{
"rate": {
"2022-01-01": 0.2,
},
"threshold": {
"2022-01-01": 100,
}
}
]
},
"normal_parameter": {
"2022-01-01": 5
}
}
}
})

# Get descendants which are parameters (ignore nodes)
parameter_descendants = list(filter(lambda p: isinstance(p, Parameter), parameters.get_descendants()))

# Check that the expected names are in the descendants
parameter_names = list(map(lambda p: p.name, parameter_descendants))
assert all(name in parameter_names for name in [
"parameters.root_node.first_child.scale_parameter[0].rate",
"parameters.root_node.first_child.scale_parameter[0].threshold",
"parameters.root_node.first_child.scale_parameter[1].rate",
"parameters.root_node.first_child.scale_parameter[1].threshold",
]), "ParameterScale descendants don't include bracket thresholds and rates"