Skip to content

Commit

Permalink
fix: import PolarsDataframeSerializer (#105)
Browse files Browse the repository at this point in the history
* fix: import PolarsDataframeSerializer

* docs: update CHANGELOG.md

* fix: import PolarsDataframeSerializer
  • Loading branch information
bednar authored Aug 12, 2024
1 parent 65d64e2 commit 13eb147
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

## 0.8.0 [unreleased]

### Features

1. [#101](https://github.com/InfluxCommunity/influxdb3-python/pull/101): Add support for InfluxDB Edge (OSS) authentication

### Bug Fixes

1. [#100](https://github.com/InfluxCommunity/influxdb3-python/pull/100): InfluxDB Edge (OSS) error handling
1. [#101](https://github.com/InfluxCommunity/influxdb3-python/pull/101): Add support for InfluxDB Edge authentication
1. [#105](https://github.com/InfluxCommunity/influxdb3-python/pull/105): Importing Polars serialization module

## 0.7.0 [2024-07-11]

Expand Down
3 changes: 2 additions & 1 deletion influxdb_client_3/write_client/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def _serialize(self, record, write_precision, payload, **kwargs):
self._serialize(Point.from_dict(record, write_precision=write_precision, **kwargs),
write_precision, payload, **kwargs)
elif 'polars' in str(type(record)):
from influxdb_client_3.write_client.client.write.dataframe_serializer import PolarsDataframeSerializer
from influxdb_client_3.write_client.client.write.polars_dataframe_serializer import \
PolarsDataframeSerializer
serializer = PolarsDataframeSerializer(record, self._point_settings, write_precision, **kwargs)
self._serialize(serializer.serialize(), write_precision, payload, **kwargs)

Expand Down
36 changes: 34 additions & 2 deletions tests/test_polars_dataframe_serializer.py → tests/test_polars.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import unittest
import importlib.util
import unittest
from unittest.mock import Mock

from influxdb_client_3 import PointSettings
from influxdb_client_3 import PointSettings, InfluxDBClient3
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 @@ -29,3 +31,33 @@ def test_to_list_of_points(self):
'iot-devices,building=5a name="iot-devices",temperature=72.2 1664798460000000000'
]
self.assertEqual(expected, actual)


@unittest.skipIf(importlib.util.find_spec("polars") is None, 'Polars package not installed')
class TestWritePolars(unittest.TestCase):
def setUp(self):
self.client = InfluxDBClient3(
host="localhost",
org="my_org",
database="my_db",
token="my_token"
)

def test_write_polars(self):
import polars as pl
df = pl.DataFrame({
"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],
})
self.client._write_api._write_service = Mock(spec=WriteService)

self.client.write(
database="database",
record=df,
data_frame_measurement_name="measurement",
data_frame_timestamp_column="time",
)

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 13eb147

Please sign in to comment.