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

[bug] Round Decimal to 9 places to support DynamoDB constraints #5092

Merged
merged 9 commits into from
Jan 22, 2020

Conversation

domsammut
Copy link
Contributor

@domsammut domsammut commented Jan 20, 2020

Proposed changes:
No rounding is currently performed prior to saving to DynamoDB tracker on Decimal values. This can result in saving errors if a value is greater than 38 characters.

Rounded to 9 decimal places as per @akelad's recommendation 🙂

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@claassistantio
Copy link

claassistantio commented Jan 20, 2020

CLA assistant check
All committers have signed the CLA.

@akelad akelad requested a review from wochinge January 20, 2020 12:42
Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

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

Thanks so much for your PR! 🥇Looks really great, added 3 minor comments, then we can merge it :-)

@@ -477,7 +477,7 @@ def replace_floats_with_decimals(obj: Union[List, Dict]) -> Any:
obj[j] = replace_floats_with_decimals(obj[j])
return obj
elif isinstance(obj, float):
return Decimal(obj)
return round(Decimal(obj), 9)
Copy link
Contributor

Choose a reason for hiding this comment

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

7 should even be enough (I just checked how many decimals time.time() returns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function will also consume confidence scores, hence the slightly higher value:

{'event': 'user', 'timestamp': Decimal('1579507733.1107571125030517578125'), 'text': 'hi', 'parse_data': {'intent': {'name': 'greet', 'confidence': Decimal('0.918040672051180450807805755175650119781494140625')}

@@ -465,7 +465,7 @@ def replace_floats_with_decimals(obj: Union[List, Dict]) -> Any:
Args:
obj: A `List` or `Dict` object.

Returns: An object with all matching values and `float` type replaced by `Decimal`.
Returns: An object with all matching values and `float` type replaced by `Decimal` rounded to 9 decimal places.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Returns: An object with all matching values and `float` type replaced by `Decimal` rounded to 9 decimal places.
Returns: An object with all matching values and `float` type replaced by `Decimal` rounded to 9 decimal places.
Suggested change
Returns: An object with all matching values and `float` type replaced by `Decimal` rounded to 9 decimal places.
Returns: An object with all matching values and `float` types replaced by `Decimal`s rounded to 9 decimal places.

@@ -98,6 +98,7 @@ def test_float_conversion_to_decimal():
d = {
"int": -1,
"float": 2.1,
"float_round": 0.918040672051180450807805755175650119781494140625,
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please to the test with an output of time.time(). I think that's the more realistic setting for the tracker store.

@@ -477,7 +477,7 @@ def replace_floats_with_decimals(obj: Union[List, Dict]) -> Any:
obj[j] = replace_floats_with_decimals(obj[j])
return obj
elif isinstance(obj, float):
return Decimal(obj)
return round(Decimal(obj), 9)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make the number of decimals a parameter of the function? 9 could be the default value

- Update test to use a time.time() value instead of a confidence score
- Add parameter to replace_floats_with_decimals() for setting the rounding precision defaulting to 9 decimal places
Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

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

left two small comment regarding then, we are ready to merge 🎉

rasa/core/utils.py Outdated Show resolved Hide resolved
rasa/core/utils.py Show resolved Hide resolved
Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

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

Aaaand we merge 🎉 Thanks again @domsammut !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants