@@ -201,20 +201,33 @@ def test_write_points_from_dataframe_with_tag_cols_and_defaults(self):
201
201
def test_write_points_from_dataframe_with_tag_escaped (self ):
202
202
now = pd .Timestamp ('1970-01-01 00:00+00:00' )
203
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" ])
204
+ data = [
205
+ ['blue orange' , "1" , 1 , 'hot=cold' ], # space, equal
206
+ ['red,green' , "2" , 2 , r'cold\fire' ], # comma, backslash
207
+ ['some' , "2" , 2 , '' ], # skip empty
208
+ ['some' , "2" , 2 , None ], # skip None
209
+ ['' , "2" , 2 , None ], # all tags empty
210
+ ],
211
+ index = pd .period_range (now , freq = 'H' , periods = 5 ),
212
+ columns = ["tag_one" , "column_one" , "column_two" , "tag_three" ]
213
+ )
210
214
211
215
expected_escaped_tags = (
212
- b"foo,tag_one=blue "
216
+ b"foo,tag_one=blue\\ orange,tag_three=hot \\ =cold "
213
217
b"column_one=\" 1\" ,column_two=1i "
214
218
b"0\n "
215
- b"foo,tag_one=red\\ ,green\\ =orange "
219
+ b"foo,tag_one=red\\ ,green,tag_three=cold \\ \\ fire "
216
220
b"column_one=\" 2\" ,column_two=2i "
217
221
b"3600000000000\n "
222
+ b"foo,tag_one=some "
223
+ b"column_one=\" 2\" ,column_two=2i "
224
+ b"7200000000000\n "
225
+ b"foo,tag_one=some "
226
+ b"column_one=\" 2\" ,column_two=2i "
227
+ b"10800000000000\n "
228
+ b"foo "
229
+ b"column_one=\" 2\" ,column_two=2i "
230
+ b"14400000000000\n "
218
231
)
219
232
220
233
with requests_mock .Mocker () as m :
@@ -224,7 +237,7 @@ def test_write_points_from_dataframe_with_tag_escaped(self):
224
237
cli = DataFrameClient (database = 'db' )
225
238
cli .write_points (dataframe , 'foo' ,
226
239
field_columns = ['column_one' , 'column_two' ],
227
- tag_columns = ['tag_one' ])
240
+ tag_columns = ['tag_one' , 'tag_three' ])
228
241
self .assertEqual (m .last_request .body , expected_escaped_tags )
229
242
230
243
def test_write_points_from_dataframe_with_numeric_column_names (self ):
0 commit comments