Skip to content

Commit 35732cd

Browse files
tzonghaoxginn8
authored andcommitted
DataFrameClient should escape measurement names (influxdata#542)
* Fixed: DataFrameClient should escape measurement names Issue influxdata#520 * Fix pep257 error
1 parent 6b5db78 commit 35732cd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

influxdb/_dataframe_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ def format_line(line):
376376
del field_df
377377

378378
# Generate line protocol string
379+
measurement = _escape_tag(measurement)
379380
points = (measurement + tags + ' ' + fields + ' ' + time).tolist()
380381
return points
381382

influxdb/tests/dataframe_client_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ def test_write_points_from_dataframe(self):
5959
cli.write_points(dataframe, 'foo', tags=None)
6060
self.assertEqual(m.last_request.body, expected)
6161

62+
def test_dataframe_write_points_with_whitespace_measurement(self):
63+
"""write_points should escape white space in measurements."""
64+
now = pd.Timestamp('1970-01-01 00:00+00:00')
65+
dataframe = pd.DataFrame(data=[["1", 1, 1.0], ["2", 2, 2.0]],
66+
index=[now, now + timedelta(hours=1)],
67+
columns=["column_one", "column_two",
68+
"column_three"])
69+
expected = (
70+
b"meas\\ with\\ space "
71+
b"column_one=\"1\",column_two=1i,column_three=1.0 0\n"
72+
b"meas\\ with\\ space "
73+
b"column_one=\"2\",column_two=2i,column_three=2.0 "
74+
b"3600000000000\n"
75+
)
76+
with requests_mock.Mocker() as m:
77+
m.register_uri(requests_mock.POST,
78+
"http://localhost:8086/write",
79+
status_code=204)
80+
cli = DataFrameClient(database='db')
81+
cli.write_points(dataframe, 'meas with space')
82+
self.assertEqual(m.last_request.body, expected)
83+
6284
def test_write_points_from_dataframe_with_none(self):
6385
"""Test write points from df in TestDataFrameClient object."""
6486
now = pd.Timestamp('1970-01-01 00:00+00:00')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy