@@ -108,10 +108,10 @@ def test_write_points_from_dataframe_with_tag_cols_and_global_tags(self):
108108 columns = ["tag_one" , "tag_two" , "column_one" ,
109109 "column_two" , "column_three" ])
110110 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 "
112112 b"column_one=\" 1\" ,column_two=1i,column_three=1.0 "
113113 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 "
115115 b"column_one=\" 2\" ,column_two=2i,column_three=2.0 "
116116 b"3600000000000\n "
117117 )
@@ -155,10 +155,10 @@ def test_write_points_from_dataframe_with_tag_cols_and_defaults(self):
155155 )
156156
157157 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 "
159159 b"column_one=\" 1\" ,column_two=1i,column_three=1.0 "
160160 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 "
162162 b"column_one=\" 2\" ,column_two=2i,column_three=2.0 "
163163 b"3600000000000\n "
164164 )
@@ -198,6 +198,35 @@ def test_write_points_from_dataframe_with_tag_cols_and_defaults(self):
198198 cli .write_points (dataframe , 'foo' )
199199 self .assertEqual (m .last_request .body , expected_no_tags_no_fields )
200200
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+
201230 def test_write_points_from_dataframe_with_numeric_column_names (self ):
202231 now = pd .Timestamp ('1970-01-01 00:00+00:00' )
203232 # df with numeric column names
0 commit comments