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

Keep float as float32 when outputting them #708

Merged
merged 5 commits into from
Aug 8, 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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

### 23.5.1 [#708](https://github.com/openfisca/openfisca-core/pull/708)

- Remove the irrelevant decimals that were added at the end of `float` results in the Web API and the test runner.
- These decimals were added while converting a Numpy `float32` to a regular 64-bits Python `float`.

For instance, the former Web API response extract:

```json
"tax_incentive": {
"2017-01": 333.3333435058594
}
```

becomes:

```json
"tax_incentive": {
"2017-01": 333.33334
}
```

## 23.5.0 [#705](https://github.com/openfisca/openfisca-core/pull/705)

* On the Web API, expose a welcome message (with a 300 code) on `/` instead of a 404 error.
Expand Down
5 changes: 2 additions & 3 deletions openfisca_core/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ def assert_near(value, target_value, absolute_error_margin = None, message = '',
else:
assert (target_value == value.decode()).all(), "Expected {}, got {}".format(target_value, value)
else:

target_value = np.array(target_value).astype(float)
value = np.array(value).astype(float)
target_value = np.array(target_value).astype(np.float32)
value = np.array(value).astype(np.float32)
diff = abs(target_value - value)

if absolute_error_margin is not None:
Expand Down
2 changes: 2 additions & 0 deletions openfisca_web_api_preview/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def calculate():

if variable.value_type == Enum:
entity_result = result.decode()[entity_index].name
elif variable.value_type == float:
entity_result = float(str(result[entity_index])) # To turn the float32 into a regular float without adding confusing extra decimals. There must be a better way.
Copy link
Member

Choose a reason for hiding this comment

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

I guess we didn't find a better way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, not for now, all the solutions I found involved stringinfying in some way.

else:
entity_result = result.tolist()[entity_index]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name = 'OpenFisca-Core',
version = '23.5.0',
version = '23.5.1',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down