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

Fix inconsistent access to sub-parameters #769

Merged
merged 8 commits into from
Nov 22, 2018
Merged
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Changelog

### 24.9.5 [#771](https://github.com/openfisca/openfisca-core/pull/771)
### 24.9.7 [#769](https://github.com/openfisca/openfisca-core/pull/769)

- Unify the protocol for appending sub-parameters
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is limpid for a user of the OpenFisca-Core library.
What does mean "appending sub-parameters" from them? Is there a protocol for that?

From the user point of view, I think what has been done here is:

- Fix an inconsistency in parameter navigation
   - In some cases, for instance while using extensions, the `parameters.path.to.subparams` notation was not working

On a meta note, I think this is another reason why the Changelog should ideally written before the review, so that it can be improve, as it's a pretty important part of each PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, too implementation-centric, thanks for the suggestion; I can pick it up on a later PR. I didn't much like "fix" as a verb though, it's too generic, and that's part of why I looked for more specific terms. How about

  • Ensure path.to.parameter syntax works consistently across country and extension

On the meta level: fixing unnecessary merge conflicts is one of the least appealing parts of the merge process at the moment, so much I'd make the diametrically opposed policy proposal, i.e. delay the CHANGELOG.md/setup.py until just before merge.

As a "best of both worlds" proposal, I suggest improving the description collaboratively by editing the PR's description at review time. Then creating the CHANGELOG entry is a matter of copy/paste (until we automate it away).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Never mind, I hadn't seen the fixup PR.)

Copy link
Member

Choose a reason for hiding this comment

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

We can include the fixup PR content in another PR to come (especially as right now editing the changelog triggers the version bump requirement), and feel free to edit the text it if you like.


### 24.9.6 [#771](https://github.com/openfisca/openfisca-core/pull/771)

- Improve serve command by documenting the bind option
- Avoid crashing when no arguments are supplied

### 24.9.4 [#774](https://github.com/openfisca/openfisca-core/pull/774)
### 24.9.5 [#774](https://github.com/openfisca/openfisca-core/pull/774)

- Clarify the error message when assigning a value larger than MaxInt32 to an 'int' variable

Expand Down
18 changes: 9 additions & 9 deletions openfisca_core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,13 @@ def __init__(self, name = "", directory_path = None, data = None, file_path = No
else:
child_name_expanded = _compose_name(name, child_name)
child = load_parameter_file(child_path, child_name_expanded)
self.children[child_name] = child
setattr(self, child_name, child)
self.add_child(child_name, child)

elif os.path.isdir(child_path):
child_name = os.path.basename(child_path)
child_name_expanded = _compose_name(name, child_name)
child = ParameterNode(child_name_expanded, directory_path = child_path)
self.children[child_name] = child
setattr(self, child_name, child)
self.add_child(child_name, child)

else:
self.file_path = file_path
Expand All @@ -404,8 +402,7 @@ def __init__(self, name = "", directory_path = None, data = None, file_path = No
child_name = str(child_name)
child_name_expanded = _compose_name(name, child_name)
child = _parse_child(child_name_expanded, child, file_path)
self.children[child_name] = child
setattr(self, child_name, child)
self.add_child(child_name, child)

def __call__(self, instant):
return self.get_at_instant(instant)
Expand All @@ -424,7 +421,7 @@ def merge(self, other):
In case of child name conflict, the other node child will replace the current node child.
"""
for child_name, child in other.children.items():
self.children[child_name] = child
self.add_child(child_name, child)

def add_child(self, name, child):
"""
Expand Down Expand Up @@ -481,8 +478,11 @@ def __init__(self, name, node, instant_str):
for child_name, child in node.children.items():
child_at_instant = child._get_at_instant(instant_str)
if child_at_instant is not None:
self._children[child_name] = child_at_instant
setattr(self, child_name, child_at_instant)
self.add_child(child_name, child_at_instant)

def add_child(self, child_name, child_at_instant):
self._children[child_name] = child_at_instant
setattr(self, child_name, child_at_instant)

def __getattr__(self, key):
param_name = _compose_name(self._name, item_name = key)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

setup(
name = 'OpenFisca-Core',
version = '24.9.6',
version = '24.9.7',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down
13 changes: 10 additions & 3 deletions tests/core/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from openfisca_country_template import CountryTaxBenefitSystem


tbs = CountryTaxBenefitSystem()


Expand All @@ -11,13 +12,19 @@ def test_extension_not_already_loaded():


def test_load_extension():
tbs = CountryTaxBenefitSystem()
assert tbs.get_variable('local_town_child_allowance') is None

tbs.load_extension('openfisca_extension_template')

assert tbs.get_variable('local_town_child_allowance') is not None


def test_unload_extensions():
tbs = CountryTaxBenefitSystem()
assert tbs.get_variable('local_town_child_allowance') is None
def test_access_to_parameters():
tbs.load_extension('openfisca_extension_template')

assert tbs.parameters('2016-01').local_town.child_allowance.amount == 100.0
assert tbs.parameters.local_town.child_allowance.amount('2016-01') == 100.0


@raises(ValueError)
Expand Down