def test_serialize_strings_with_commas(self): from influxdb_client.extras import pd csv = StringIO("""sep=; Date;Entry Type;Value;Currencs;Category;Person;Account;Counter Account;Group;Note;Recurring; "01.10.2018";"Expense";"-1,00";"EUR";"Testcategory";"";"Testaccount";"";"";"This, works";"no"; "02.10.2018";"Expense";"-1,00";"EUR";"Testcategory";"";"Testaccount";"";"";"This , works not";"no"; """) data_frame = pd.read_csv(csv, sep=";", skiprows=1, decimal=",", encoding="utf-8") data_frame['Date'] = pd.to_datetime(data_frame['Date'], format="%d.%m.%Y") data_frame.set_index('Date', inplace=True) points = data_frame_to_list_of_points( data_frame=data_frame, data_frame_measurement_name="bookings", data_frame_tag_columns=[ 'Entry Type', 'Category', 'Person', 'Account' ], point_settings=PointSettings()) self.assertEqual(2, len(points)) self.assertEqual( "bookings,Account=Testaccount,Category=Testcategory,Entry\\ Type=Expense Currencs=\"EUR\",Note=\"This, works\",Recurring=\"no\",Value=-1.0 1538352000000000000", points[0]) self.assertEqual( "bookings,Account=Testaccount,Category=Testcategory,Entry\\ Type=Expense Currencs=\"EUR\",Note=\"This , works not\",Recurring=\"no\",Value=-1.0 1538438400000000000", points[1])
def test_write_data_frame(self): import random from influxdb_client.extras import pd if not os.path.isfile("data_frame_file.csv"): with open('data_frame_file.csv', mode='w+') as csv_file: _writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) _writer.writerow([ 'time', 'col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8' ]) for i in range(1, 1500000): choice = ['test_a', 'test_b', 'test_c'] _writer.writerow([ i, random.choice(choice), 'test', random.random(), random.random(), random.random(), random.random(), random.random(), random.random() ]) csv_file.close() with open('data_frame_file.csv', mode='rb') as csv_file: data_frame = pd.read_csv(csv_file, index_col='time') print(data_frame) print('Writing...') start = time.time() self._write_client.write("my-bucket", "my-org", record=data_frame, data_frame_measurement_name='h2o_feet', data_frame_tag_columns=['location']) self._write_client.__del__() print("Time elapsed: ", (time.time() - start)) csv_file.close()