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

Commit 896f623

Browse files
authored
chore(line_protocol): update repr value of floats to properly handle precision (#813)
* chore(line_protocol): update repr value of floats to properly handle precision. Closes #488 * chore(line_protocol): fix repr and handle boolean values * chore(CHANGELOG): update to include reference to PR#488
1 parent 57c1408 commit 896f623

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2525
- Update make_lines section in line_protocol.py to split out core function (#375 thx @aisbaa)
2626
- Fix nanosecond time resolution for points (#407 thx @AndreCAndersen && @clslgrnc)
2727
- Fix import of distutils.spawn (#805 thx @Hawk777)
28+
- Update repr of float values including properly handling of boolean (#488 thx @ghost)
2829

2930
### Removed
3031

influxdb/line_protocol.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ def _escape_value(value):
112112
if isinstance(value, integer_types) and not isinstance(value, bool):
113113
return str(value) + 'i'
114114

115+
if isinstance(value, bool):
116+
return str(value)
117+
115118
if _is_float(value):
116-
return repr(value)
119+
return repr(float(value))
117120

118121
return str(value)
119122

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(0.8289445733333332),
180+
}
181+
}
182+
]
183+
}
184+
self.assertEqual(
185+
line_protocol.make_lines(data),
186+
'test float_val=0.8289445733333332\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