|
1 | 1 | import time
|
2 | 2 | import unittest
|
3 | 3 | from datetime import timedelta
|
| 4 | +from io import StringIO |
4 | 5 |
|
5 | 6 | from influxdb_client import InfluxDBClient, WriteOptions, WriteApi, WritePrecision
|
6 | 7 | from influxdb_client.client.write.dataframe_serializer import data_frame_to_list_of_points, DataframeSerializer
|
@@ -374,6 +375,27 @@ def test_index_not_periodIndex_respect_write_precision(self):
|
374 | 375 | self.assertEqual(1, len(points))
|
375 | 376 | self.assertEqual(f"h2o level=15i {precision[1]}", points[0])
|
376 | 377 |
|
| 378 | + def test_serialize_strings_with_commas(self): |
| 379 | + from influxdb_client.extras import pd |
| 380 | + |
| 381 | + csv = StringIO("""sep=; |
| 382 | +Date;Entry Type;Value;Currencs;Category;Person;Account;Counter Account;Group;Note;Recurring; |
| 383 | +"01.10.2018";"Expense";"-1,00";"EUR";"Testcategory";"";"Testaccount";"";"";"This, works";"no"; |
| 384 | +"02.10.2018";"Expense";"-1,00";"EUR";"Testcategory";"";"Testaccount";"";"";"This , works not";"no"; |
| 385 | +""") |
| 386 | + data_frame = pd.read_csv(csv, sep=";", skiprows=1, decimal=",", encoding="utf-8") |
| 387 | + data_frame['Date'] = pd.to_datetime(data_frame['Date'], format="%d.%m.%Y") |
| 388 | + data_frame.set_index('Date', inplace=True) |
| 389 | + |
| 390 | + points = data_frame_to_list_of_points(data_frame=data_frame, |
| 391 | + data_frame_measurement_name="bookings", |
| 392 | + data_frame_tag_columns=['Entry Type', 'Category', 'Person', 'Account'], |
| 393 | + point_settings=PointSettings()) |
| 394 | + |
| 395 | + self.assertEqual(2, len(points)) |
| 396 | + self.assertEqual("bookings,Account=Testaccount,Category=Testcategory,Entry\\ Type=Expense Currencs=\"EUR\",Note=\"This, works\",Recurring=\"no\",Value=-1.0 1538352000000000000", points[0]) |
| 397 | + self.assertEqual("bookings,Account=Testaccount,Category=Testcategory,Entry\\ Type=Expense Currencs=\"EUR\",Note=\"This , works not\",Recurring=\"no\",Value=-1.0 1538438400000000000", points[1]) |
| 398 | + |
377 | 399 |
|
378 | 400 | class DataSerializerChunksTest(unittest.TestCase):
|
379 | 401 | def test_chunks(self):
|
|
0 commit comments