Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge 459eec8 into 7c858bf
Browse files Browse the repository at this point in the history
  • Loading branch information
sebito91 committed Apr 9, 2020
2 parents 7c858bf + 459eec8 commit e586e9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion influxdb/line_protocol.py
Expand Up @@ -113,7 +113,7 @@ def _escape_value(value):
return str(value) + 'i'

if _is_float(value):
return repr(value)
return repr(float(value))

return str(value)

Expand Down
23 changes: 21 additions & 2 deletions influxdb/tests/test_line_protocol.py
Expand Up @@ -6,10 +6,12 @@
from __future__ import print_function
from __future__ import unicode_literals

from datetime import datetime
import unittest
from pytz import UTC, timezone

from datetime import datetime
from decimal import Decimal

from pytz import UTC, timezone
from influxdb import line_protocol


Expand Down Expand Up @@ -166,3 +168,20 @@ def test_float_with_long_decimal_fraction(self):
line_protocol.make_lines(data),
'test float_val=1.0000000000000009\n'
)

def test_float_with_long_decimal_fraction_as_type_decimal(self):
"""Ensure precision is preserved when casting Decimal into strings."""
data = {
"points": [
{
"measurement": "test",
"fields": {
"float_val": Decimal(1.0000000000000009),
}
}
]
}
self.assertEqual(
line_protocol.make_lines(data),
'test float_val=1.0000000000000009\n'
)

0 comments on commit e586e9d

Please sign in to comment.