1
- import csv
2
- import os
3
1
import time
4
2
import unittest
5
3
from datetime import timedelta
@@ -160,7 +158,7 @@ def test_write_object_field_nan(self):
160
158
points [1 ])
161
159
162
160
def test_write_field_bool (self ):
163
- from influxdb_client .extras import pd , np
161
+ from influxdb_client .extras import pd
164
162
165
163
now = pd .Timestamp ('2020-04-05 00:00+00:00' )
166
164
@@ -252,7 +250,7 @@ def test_tags_order(self):
252
250
self .assertEqual ("h2o,a=a,b=b,c=c level=2i 1586048400000000000" , points [0 ])
253
251
254
252
def test_escape_text_value (self ):
255
- from influxdb_client .extras import pd , np
253
+ from influxdb_client .extras import pd
256
254
257
255
now = pd .Timestamp ('2020-04-05 00:00+00:00' )
258
256
an_hour_ago = now - timedelta (hours = 1 )
@@ -273,7 +271,7 @@ def test_escape_text_value(self):
273
271
self .assertEqual ("test,d=bar\\ foo b=\" goodbye cruel world\" ,c=2i 1586044800000000000" , points [1 ])
274
272
275
273
def test_with_default_tags (self ):
276
- from influxdb_client .extras import pd , np
274
+ from influxdb_client .extras import pd
277
275
now = pd .Timestamp ('2020-04-05 00:00+00:00' )
278
276
data_frame = pd .DataFrame (data = {
279
277
'value' : [1 , 2 ],
@@ -309,8 +307,7 @@ def test_with_default_tags(self):
309
307
self .assertEqual (True , (data_frame == original_data ).all (axis = None ), f'data changed; old:\n { original_data } \n new:\n { data_frame } ' )
310
308
311
309
def test_with_period_index (self ):
312
- from influxdb_client .extras import pd , np
313
- now = pd .Timestamp ('2020-04-05 00:00+00:00' )
310
+ from influxdb_client .extras import pd
314
311
data_frame = pd .DataFrame (data = {
315
312
'value' : [1 , 2 ],
316
313
},
@@ -323,3 +320,16 @@ def test_with_period_index(self):
323
320
self .assertEqual (2 , len (points ))
324
321
self .assertEqual ("h2o value=1i 1586048400000000000" , points [0 ])
325
322
self .assertEqual ("h2o value=2i 1586052000000000000" , points [1 ])
323
+
324
+ def test_write_num_py_floats (self ):
325
+ from influxdb_client .extras import pd , np
326
+ now = pd .Timestamp ('2020-04-05 00:00+00:00' )
327
+
328
+ for np_float_type in [np .float , np .float16 , np .float32 , np .float64 , np .float128 ]:
329
+ data_frame = pd .DataFrame ([15.5 ], index = [now ], columns = ['level' ]).astype (np_float_type )
330
+ points = data_frame_to_list_of_points (data_frame = data_frame ,
331
+ data_frame_measurement_name = 'h2o' ,
332
+ point_settings = PointSettings ())
333
+ self .assertEqual (1 , len (points ))
334
+ self .assertEqual ("h2o level=15.5 1586044800000000000" , points [0 ], msg = f'Current type: { np_float_type } ' )
335
+
0 commit comments