File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -74,12 +74,22 @@ def quote_literal(value):
74
74
)
75
75
76
76
77
+ def _is_float (value ):
78
+ try :
79
+ float (value )
80
+ except ValueError :
81
+ return False
82
+ return True
83
+
84
+
77
85
def _escape_value (value ):
78
86
value = _get_unicode (value )
79
87
if isinstance (value , text_type ) and value != '' :
80
88
return quote_ident (value )
81
89
elif isinstance (value , integer_types ) and not isinstance (value , bool ):
82
90
return str (value ) + 'i'
91
+ elif _is_float (value ):
92
+ return repr (value )
83
93
else :
84
94
return str (value )
85
95
Original file line number Diff line number Diff line change @@ -119,3 +119,20 @@ def test_quote_literal(self):
119
119
line_protocol .quote_literal (r"""\foo ' bar " Örf""" ),
120
120
r"""'\\foo \' bar " Örf'"""
121
121
)
122
+
123
+ def test_float_with_long_decimal_fraction (self ):
124
+ """Ensure precision is preserved when casting floats into strings."""
125
+ data = {
126
+ "points" : [
127
+ {
128
+ "measurement" : "test" ,
129
+ "fields" : {
130
+ "float_val" : 1.0000000000000009 ,
131
+ }
132
+ }
133
+ ]
134
+ }
135
+ self .assertEqual (
136
+ line_protocol .make_lines (data ),
137
+ 'test float_val=1.0000000000000009\n '
138
+ )
You can’t perform that action at this time.
0 commit comments