From b322ca275b4da3e316ad64f8f91560e1584ea7bb Mon Sep 17 00:00:00 2001 From: Isil Demir Date: Tue, 21 Mar 2017 17:58:06 -0700 Subject: [PATCH 1/2] fix for lost precision on float field values --- influxdb/line_protocol.py | 10 ++++++++++ influxdb/tests/test_line_protocol.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/influxdb/line_protocol.py b/influxdb/line_protocol.py index 7c8c8f24..180aea31 100644 --- a/influxdb/line_protocol.py +++ b/influxdb/line_protocol.py @@ -75,12 +75,22 @@ def quote_literal(value): ) +def _is_float(value): + try: + float(value) + except ValueError: + return False + return True + + def _escape_value(value): value = _get_unicode(value) if isinstance(value, text_type) and value != '': return quote_ident(value) elif isinstance(value, integer_types) and not isinstance(value, bool): return str(value) + 'i' + elif _is_float(value): + return repr(value) else: return str(value) diff --git a/influxdb/tests/test_line_protocol.py b/influxdb/tests/test_line_protocol.py index 726f8705..fc45971e 100644 --- a/influxdb/tests/test_line_protocol.py +++ b/influxdb/tests/test_line_protocol.py @@ -119,3 +119,19 @@ def test_quote_literal(self): line_protocol.quote_literal(r"""\foo ' bar " Örf"""), r"""'\\foo \' bar " Örf'""" ) + + def test_float_with_long_decimal_fraction(self): + data = { + "points": [ + { + "measurement": "test", + "fields": { + "float_val": 1.0000000000000009, + } + } + ] + } + self.assertEqual( + line_protocol.make_lines(data), + 'test float_val=1.0000000000000009\n' + ) From eb049f197e76575e53ff883ecd2eff05c519da00 Mon Sep 17 00:00:00 2001 From: Isil Demir Date: Wed, 5 Apr 2017 17:14:46 -0700 Subject: [PATCH 2/2] docstring for pep257 compliance --- influxdb/tests/test_line_protocol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/influxdb/tests/test_line_protocol.py b/influxdb/tests/test_line_protocol.py index fc45971e..61f54557 100644 --- a/influxdb/tests/test_line_protocol.py +++ b/influxdb/tests/test_line_protocol.py @@ -121,6 +121,7 @@ def test_quote_literal(self): ) def test_float_with_long_decimal_fraction(self): + """Ensure precision is preserved when casting floats into strings.""" data = { "points": [ { 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