@@ -365,16 +365,18 @@ def _convert_dataframe_to_lines(self,
365
365
366
366
# Make an array of formatted field keys and values
367
367
field_df = dataframe [field_columns ]
368
+ # Keep the positions where Null values are found
369
+ mask_null = field_df .isnull ().values
368
370
369
371
field_df = self ._stringify_dataframe (field_df ,
370
372
numeric_precision ,
371
373
datatype = 'field' )
372
374
373
- def format_line ( line ):
374
- line = line [ ~ line . isnull ()] # drop None entries
375
- return "," . join (( line . index + '=' + line . values ))
376
-
377
- fields = field_df .apply ( format_line , axis = 1 )
375
+ field_df = ( field_df . columns . values + '=' ). tolist () + field_df
376
+ field_df [ field_df . columns [ 1 :]] = ',' + field_df [
377
+ field_df . columns [ 1 :]]
378
+ field_df = field_df . where ( ~ mask_null , '' ) # drop Null entries
379
+ fields = field_df .sum ( axis = 1 )
378
380
del field_df
379
381
380
382
# Generate line protocol string
@@ -388,9 +390,6 @@ def _stringify_dataframe(dframe, numeric_precision, datatype='field'):
388
390
# Prevent modification of input dataframe
389
391
dframe = dframe .copy ()
390
392
391
- # Keep the positions where Null values are found
392
- mask_null = dframe .isnull ().values
393
-
394
393
# Find int and string columns for field-type data
395
394
int_columns = dframe .select_dtypes (include = ['integer' ]).columns
396
395
string_columns = dframe .select_dtypes (include = ['object' ]).columns
@@ -435,7 +434,6 @@ def _stringify_dataframe(dframe, numeric_precision, datatype='field'):
435
434
436
435
dframe .columns = dframe .columns .astype (str )
437
436
438
- dframe = dframe .where (~ mask_null , None )
439
437
return dframe
440
438
441
439
def _datetime_to_epoch (self , datetime , time_precision = 's' ):
0 commit comments