Skip to content

Commit

Permalink
feat: support for writing pandas DataFrame (#79) - check if measureme…
Browse files Browse the repository at this point in the history
…nt name is in kwargs
  • Loading branch information
rolincova committed May 4, 2020
1 parent 3a3aab8 commit f951d43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions influxdb_client/client/write_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ def _data_frame_to_list_of_points(self, data_frame, precision, **kwargs):
raise TypeError('Must be DataFrame, but type was: {0}.'
.format(type(data_frame)))

if 'data_frame_measurement_name' not in kwargs:
raise TypeError('"data_frame_measurement_name" is a Required Argument')

if isinstance(data_frame.index, pd.PeriodIndex):
data_frame.index = data_frame.index.to_timestamp()
else:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_WriteApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ def test_write_data_frame(self):

self.delete_test_bucket(bucket)

def test_write_data_frame_without_measurement_name(self):
from influxdb_client.extras import pd

bucket = self.create_test_bucket()

now = pd.Timestamp('1970-01-01 00:00+00:00')
data_frame = pd.DataFrame(data=[["coyote_creek", 1.0], ["coyote_creek", 2.0]],
index=[now + timedelta(hours=1), now + timedelta(hours=2)],
columns=["location", "water_level"])

with self.assertRaises(TypeError) as cm:
self.write_client.write(bucket.name, record=data_frame)
exception = cm.exception

self.assertEqual('"data_frame_measurement_name" is a Required Argument', exception.__str__())

def test_use_default_org(self):
bucket = self.create_test_bucket()

Expand Down

0 comments on commit f951d43

Please sign in to comment.