def test_write_num_py(self): from influxdb_client.extras import pd, np bucket = self.create_test_bucket() now = pd.Timestamp('2020-04-05 00:00+00:00') data_frame = pd.DataFrame( data=[["coyote_creek", np.int64(100.5)], ["coyote_creek", np.int64(200)]], index=[now + timedelta(hours=1), now + timedelta(hours=2)], columns=["location", "water_level"]) write_api = self.client.write_api(write_options=SYNCHRONOUS) write_api.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet', data_frame_tag_columns=['location']) write_api.close() result = self.query_api.query( "from(bucket:\"" + bucket.name + "\") |> range(start: 1970-01-01T00:00:00.000000001Z)", self.my_organization.id) self.assertEqual(1, len(result)) self.assertEqual(2, len(result[0].records)) self.assertEqual(result[0].records[0].get_value(), 100.0) self.assertEqual(result[0].records[1].get_value(), 200.0) pass
def test_escaping_measurement(self): from influxdb_client.extras import pd, np now = pd.Timestamp('2020-04-05 00:00+00:00') data_frame = pd.DataFrame(data=[ ["coyote_creek", np.int64(100.5)], ["coyote_creek", np.int64(200)], ], index=[now + timedelta(hours=1), now + timedelta(hours=2)], columns=["location", "water_level"]) points = data_frame_to_list_of_points(data_frame=data_frame, point_settings=PointSettings(), data_frame_measurement_name='measu rement', data_frame_tag_columns={"tag"}) self.assertEqual(2, len(points)) self.assertEqual("measu\\ rement location=\"coyote_creek\",water_level=100i 1586048400000000000", points[0]) self.assertEqual("measu\\ rement location=\"coyote_creek\",water_level=200i 1586052000000000000", points[1]) points = data_frame_to_list_of_points(data_frame=data_frame, point_settings=PointSettings(), data_frame_measurement_name='measu\nrement2', data_frame_tag_columns={"tag"}) self.assertEqual(2, len(points)) self.assertEqual("measu\\nrement2 location=\"coyote_creek\",water_level=100i 1586048400000000000", points[0]) self.assertEqual("measu\\nrement2 location=\"coyote_creek\",water_level=200i 1586052000000000000", points[1])
def test_tag_escaping_key_and_value(self): from influxdb_client.extras import pd, np now = pd.Timestamp('2020-04-05 00:00+00:00') data_frame = pd.DataFrame( data=[ ["carriage\nreturn", "new\nline", "t\tab", np.int64(2)], ], index=[ now + timedelta(hours=1), ], columns=["carriage\rreturn", "new\nline", "t\tab", "l\ne\rv\tel"]) points = data_frame_to_list_of_points( data_frame=data_frame, point_settings=PointSettings(), data_frame_measurement_name='h\n2\ro\t_data', data_frame_tag_columns={"new\nline", "carriage\rreturn", "t\tab"}) self.assertEqual(1, len(points)) self.assertEqual( "h\\n2\\ro\\t_data,carriage\\rreturn=carriage\\nreturn,new\\nline=new\\nline,t\\tab=t\\tab l\\ne\\rv\\tel=2i 1586048400000000000", points[0])
def test_tags_order(self): from influxdb_client.extras import pd, np now = pd.Timestamp('2020-04-05 00:00+00:00') data_frame = pd.DataFrame(data=[["c", "a", "b", np.int64(2)], ], index=[now + timedelta(hours=1), ], columns=["c", "a", "b", "level"]) points = data_frame_to_list_of_points(data_frame=data_frame, point_settings=PointSettings(), data_frame_measurement_name='h2o', data_frame_tag_columns={"c", "a", "b"}) self.assertEqual(1, len(points)) self.assertEqual("h2o,a=a,b=b,c=c level=2i 1586048400000000000", points[0])
def test_numpy_types(self): from influxdb_client.extras import np point = Point.measurement("h2o") \ .tag("location", "europe") \ .field("np.float1", np.float(1.123)) \ .field("np.float2", np.float16(2.123)) \ .field("np.float3", np.float32(3.123)) \ .field("np.float4", np.float64(4.123)) \ .field("np.int1", np.int8(1)) \ .field("np.int2", np.int16(2)) \ .field("np.int3", np.int32(3)) \ .field("np.int4", np.int64(4)) \ .field("np.uint1", np.uint8(5)) \ .field("np.uint2", np.uint16(6)) \ .field("np.uint3", np.uint32(7)) \ .field("np.uint4", np.uint64(8)) self.assertEqual( "h2o,location=europe np.float1=1.123,np.float2=2.123,np.float3=3.123,np.float4=4.123,np.int1=1i,np.int2=2i,np.int3=3i,np.int4=4i,np.uint1=5i,np.uint2=6i,np.uint3=7i,np.uint4=8i", point.to_line_protocol())