Skip to content

Commit

Permalink
fix: import PolarsDataframeSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Aug 12, 2024
1 parent 60a7e3d commit 6a14269
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tests/test_polars.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import unittest
import importlib.util
import unittest
from unittest.mock import Mock

from influxdb_client_3 import PointSettings, InfluxDBClient3
from influxdb_client_3.write_client.client.write_api import WriteApi

from influxdb_client_3.write_client import WriteService
from influxdb_client_3.write_client.client.write.polars_dataframe_serializer import polars_data_frame_to_list_of_points


Expand Down Expand Up @@ -47,11 +46,10 @@ def setUp(self):
def test_write_polars(self):
import polars as pl
df = pl.DataFrame({
"time": ["2024-08-01 00:00:00", "2024-08-01 01:00:00"],
"time": pl.Series(["2024-08-01 00:00:00", "2024-08-01 01:00:00"]).str.to_datetime(time_unit='ns'),
"temperature": [22.4, 21.8],
})
mock_write = Mock(spec=WriteApi)
self.client._write_api.write = mock_write.write
self.client._write_api._write_service = Mock(spec=WriteService)

self.client.write(
database="database",
Expand All @@ -60,5 +58,6 @@ def test_write_polars(self):
data_frame_timestamp_column="time",
)

from polars.testing import assert_frame_equal
assert_frame_equal(df, self.client._write_api.write.call_args[1]['record'])
actual = self.client._write_api._write_service.post_write.call_args[1]['body']
self.assertEqual(b'measurement temperature=22.4 1722470400000000000\n'
b'measurement temperature=21.8 1722474000000000000', actual)

0 comments on commit 6a14269

Please sign in to comment.