@@ -108,10 +108,10 @@ def test_write_points_from_dataframe_with_tag_cols_and_global_tags(self):
108
108
columns = ["tag_one" , "tag_two" , "column_one" ,
109
109
"column_two" , "column_three" ])
110
110
expected = (
111
- b"foo,tag_one=blue,tag_two=1,global_tag=value "
111
+ b"foo,global_tag=value, tag_one=blue,tag_two=1 "
112
112
b"column_one=\" 1\" ,column_two=1i,column_three=1.0 "
113
113
b"0\n "
114
- b"foo,tag_one=red,tag_two=0,global_tag=value "
114
+ b"foo,global_tag=value, tag_one=red,tag_two=0 "
115
115
b"column_one=\" 2\" ,column_two=2i,column_three=2.0 "
116
116
b"3600000000000\n "
117
117
)
@@ -155,10 +155,10 @@ def test_write_points_from_dataframe_with_tag_cols_and_defaults(self):
155
155
)
156
156
157
157
expected_fields_no_tags = (
158
- b"foo,tag_one=blue,tag_two=1, tag_three=hot "
158
+ b"foo,tag_one=blue,tag_three=hot,tag_two=1 "
159
159
b"column_one=\" 1\" ,column_two=1i,column_three=1.0 "
160
160
b"0\n "
161
- b"foo,tag_one=red,tag_two=0, tag_three=cold "
161
+ b"foo,tag_one=red,tag_three=cold,tag_two=0 "
162
162
b"column_one=\" 2\" ,column_two=2i,column_three=2.0 "
163
163
b"3600000000000\n "
164
164
)
@@ -198,6 +198,35 @@ def test_write_points_from_dataframe_with_tag_cols_and_defaults(self):
198
198
cli .write_points (dataframe , 'foo' )
199
199
self .assertEqual (m .last_request .body , expected_no_tags_no_fields )
200
200
201
+ def test_write_points_from_dataframe_with_tag_escaped (self ):
202
+ now = pd .Timestamp ('1970-01-01 00:00+00:00' )
203
+ dataframe = pd .DataFrame (
204
+ data = [['blue' , 1 , "1" , 1 , 1.0 , 'hot' ],
205
+ ['red,green=orange' , 0 , "2" , 2 , 2.0 , 'cold' ]],
206
+ index = [now , now + timedelta (hours = 1 )],
207
+ columns = ["tag_one" , "tag_two" , "column_one" ,
208
+ "column_two" , "column_three" ,
209
+ "tag_three" ])
210
+
211
+ expected_escaped_tags = (
212
+ b"foo,tag_one=blue "
213
+ b"column_one=\" 1\" ,column_two=1i "
214
+ b"0\n "
215
+ b"foo,tag_one=red\\ ,green\\ =orange "
216
+ b"column_one=\" 2\" ,column_two=2i "
217
+ b"3600000000000\n "
218
+ )
219
+
220
+ with requests_mock .Mocker () as m :
221
+ m .register_uri (requests_mock .POST ,
222
+ "http://localhost:8086/write" ,
223
+ status_code = 204 )
224
+ cli = DataFrameClient (database = 'db' )
225
+ cli .write_points (dataframe , 'foo' ,
226
+ field_columns = ['column_one' , 'column_two' ],
227
+ tag_columns = ['tag_one' ])
228
+ self .assertEqual (m .last_request .body , expected_escaped_tags )
229
+
201
230
def test_write_points_from_dataframe_with_numeric_column_names (self ):
202
231
now = pd .Timestamp ('1970-01-01 00:00+00:00' )
203
232
# df with numeric column names
0 commit comments