@@ -69,7 +69,7 @@ def test_write_points_from_dataframe_in_batches(self):
69
69
cli = DataFrameClient (database = 'db' )
70
70
self .assertTrue (cli .write_points (dataframe , "foo" , batch_size = 1 ))
71
71
72
- def test_write_points_with_tag_columns (self ):
72
+ def test_write_points_from_dataframe_with_tag_columns (self ):
73
73
now = pd .Timestamp ('1970-01-01 00:00+00:00' )
74
74
dataframe = pd .DataFrame (data = [['blue' , 1 , "1" , 1 , 1.0 ],
75
75
['red' , 0 , "2" , 2 , 2.0 ]],
@@ -100,7 +100,7 @@ def test_write_points_with_tag_columns(self):
100
100
tag_columns = ['tag_one' , 'tag_two' ], tags = None )
101
101
self .assertEqual (m .last_request .body , expected )
102
102
103
- def test_write_points_with_tag_columns_and_global_tags (self ):
103
+ def test_write_points_from_dataframe_with_tag_cols_and_global_tags (self ):
104
104
now = pd .Timestamp ('1970-01-01 00:00+00:00' )
105
105
dataframe = pd .DataFrame (data = [['blue' , 1 , "1" , 1 , 1.0 ],
106
106
['red' , 0 , "2" , 2 , 2.0 ]],
@@ -128,7 +128,7 @@ def test_write_points_with_tag_columns_and_global_tags(self):
128
128
tags = {'global_tag' : 'value' })
129
129
self .assertEqual (m .last_request .body , expected )
130
130
131
- def test_write_points_with_tag_columns_and_defaults (self ):
131
+ def test_write_points_from_dataframe_with_tag_cols_and_defaults (self ):
132
132
now = pd .Timestamp ('1970-01-01 00:00+00:00' )
133
133
dataframe = pd .DataFrame (data = [['blue' , 1 , "1" , 1 , 1.0 , 'hot' ],
134
134
['red' , 0 , "2" , 2 , 2.0 , 'cold' ]],
@@ -219,6 +219,50 @@ def test_write_points_from_dataframe_with_numeric_column_names(self):
219
219
220
220
self .assertEqual (m .last_request .body , expected )
221
221
222
+ def test_write_points_from_dataframe_with_numeric_precision (self ):
223
+ now = pd .Timestamp ('1970-01-01 00:00+00:00' )
224
+ # df with numeric column names
225
+ dataframe = pd .DataFrame (data = [["1" , 1 , 1.1111111111111 ],
226
+ ["2" , 2 , 2.2222222222222 ]],
227
+ index = [now , now + timedelta (hours = 1 )])
228
+
229
+ expected_default_precision = (
230
+ b'foo,hello=there 0=\" 1\" ,1=1i,2=1.11111111111 0\n '
231
+ b'foo,hello=there 0=\" 2\" ,1=2i,2=2.22222222222 3600000000000\n '
232
+ )
233
+
234
+ expected_specified_precision = (
235
+ b'foo,hello=there 0=\" 1\" ,1=1i,2=1.1111 0\n '
236
+ b'foo,hello=there 0=\" 2\" ,1=2i,2=2.2222 3600000000000\n '
237
+ )
238
+
239
+ expected_full_precision = (
240
+ b'foo,hello=there 0=\" 1\" ,1=1i,2=1.1111111111111 0\n '
241
+ b'foo,hello=there 0=\" 2\" ,1=2i,2=2.2222222222222 3600000000000\n '
242
+ )
243
+
244
+ with requests_mock .Mocker () as m :
245
+ m .register_uri (requests_mock .POST ,
246
+ "http://localhost:8086/write" ,
247
+ status_code = 204 )
248
+
249
+ cli = DataFrameClient (database = 'db' )
250
+ cli .write_points (dataframe , "foo" , {"hello" : "there" })
251
+
252
+ self .assertEqual (m .last_request .body , expected_default_precision )
253
+
254
+ cli = DataFrameClient (database = 'db' )
255
+ cli .write_points (dataframe , "foo" , {"hello" : "there" },
256
+ numeric_precision = 4 )
257
+
258
+ self .assertEqual (m .last_request .body , expected_specified_precision )
259
+
260
+ cli = DataFrameClient (database = 'db' )
261
+ cli .write_points (dataframe , "foo" , {"hello" : "there" },
262
+ numeric_precision = 'full' )
263
+
264
+ self .assertEqual (m .last_request .body , expected_full_precision )
265
+
222
266
def test_write_points_from_dataframe_with_period_index (self ):
223
267
dataframe = pd .DataFrame (data = [["1" , 1 , 1.0 ], ["2" , 2 , 2.0 ]],
224
268
index = [pd .Period ('1970-01-01' ),
0 commit comments