Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 76e0125

Browse files
committed
chore(line_protocol): update repr value of floats to properly handle precision. Closes #488
1 parent 57c1408 commit 76e0125

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

influxdb/line_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _escape_value(value):
113113
return str(value) + 'i'
114114

115115
if _is_float(value):
116-
return repr(value)
116+
return repr(float(value))
117117

118118
return str(value)
119119

influxdb/tests/test_line_protocol.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from __future__ import print_function
77
from __future__ import unicode_literals
88

9-
from datetime import datetime
109
import unittest
11-
from pytz import UTC, timezone
1210

11+
from datetime import datetime
12+
from decimal import Decimal
13+
14+
from pytz import UTC, timezone
1315
from influxdb import line_protocol
1416

1517

@@ -166,3 +168,20 @@ def test_float_with_long_decimal_fraction(self):
166168
line_protocol.make_lines(data),
167169
'test float_val=1.0000000000000009\n'
168170
)
171+
172+
def test_float_with_long_decimal_fraction_as_type_decimal(self):
173+
"""Ensure precision is preserved when casting Decimal into strings."""
174+
data = {
175+
"points": [
176+
{
177+
"measurement": "test",
178+
"fields": {
179+
"float_val": Decimal(1.0000000000000009),
180+
}
181+
}
182+
]
183+
}
184+
self.assertEqual(
185+
line_protocol.make_lines(data),
186+
'test float_val=1.0000000000000009\n'
187+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy