8000 DataFrameClient should escape measurement names by tzonghao · Pull Request #542 · influxdata/influxdb-python · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

DataFrameClient should escape measurement names #542

Merged
merged 4 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions influxdb/_dataframe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def format_line(line):
del field_df

# Generate line protocol string
measurement = _escape_tag(measurement)
points = (measurement + tags + ' ' + fields + ' ' + time).tolist()
return points

Expand Down
22 changes: 22 additions & 0 deletions influxdb/tests/dataframe_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ def test_write_points_from_dataframe(self):
cli.write_points(dataframe, 'foo', tags=None)
self.assertEqual(m.last_request.body, expected)

def test_dataframe_write_points_with_whitespace_measurement(self):
"""write_points should escape white space in measurements."""
now = pd.Timestamp('1970-01-01 00:00+00:00')
dataframe = pd.DataFrame(data=[["1", 1, 1.0], ["2", 2, 2.0]],
index=[now, now + timedelta(hours=1)],
columns=["column_one", "column_two",
"column_three"])
expected = (
b"meas\\ with\\ space "
b"column_one=\"1\",column_two=1i,column_three=1.0 0\n"
b"meas\\ with\\ space "
b"column_one=\"2\",column_two=2i,column_three=2.0 "
b"3600000000000\n"
)
with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/write",
status_code=204)
cli = DataFrameClient(database='db')
cli.write_points(dataframe, 'meas with space')
self.assertEqual(m.last_request.body, expected)

def test_write_points_from_dataframe_with_none(self):
"""Test write points from df in TestDataFrameClient object."""
now = pd.Timestamp('1970-01-01 00:00+00:00')
Expand Down
0