Skip to content

Commit b322ca2

Browse files
committed
fix for lost precision on float field values
1 parent d1aa81a commit b322ca2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

influxdb/line_protocol.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,22 @@ def quote_literal(value):
7575
)
7676

7777

78+
def _is_float(value):
79+
try:
80+
float(value)
81+
except ValueError:
82+
return False
83+
return True
84+
85+
7886
def _escape_value(value):
7987
value = _get_unicode(value)
8088
if isinstance(value, text_type) and value != '':
8189
return quote_ident(value)
8290
elif isinstance(value, integer_types) and not isinstance(value, bool):
8391
return str(value) + 'i'
92+
elif _is_float(value):
93+
return repr(value)
8494
else:
8595
return str(value)
8696

influxdb/tests/test_line_protocol.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,19 @@ def test_quote_literal(self):
119119
line_protocol.quote_literal(r"""\foo ' bar " Örf"""),
120120
r"""'\\foo \' bar " Örf'"""
121121
)
122+
123+
def test_float_with_long_decimal_fraction(self):
124+
data = {
125+
"points": [
126+
{
127+
"measurement": "test",
128+
"fields": {
129+
"float_val": 1.0000000000000009,
130+
}
131+
}
132+
]
133+
}
134+
self.assertEqual(
135+
line_protocol.make_lines(data),
136+
'test float_val=1.0000000000000009\n'
137+
)

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