@@ -37,6 +37,14 @@ def _itertuples(data_frame):
3737 return zip (data_frame .index , * cols )
3838
3939
40+ def _is_nan (x ):
41+ return x != x
42+
43+
44+ def _any_not_nan (p , indexes ):
45+ return any (map (lambda inx : not _is_nan (p [inx ]), indexes ))
46+
47+
4048def data_frame_to_list_of_points (data_frame , point_settings , ** kwargs ):
4149 """Serialize DataFrame into LineProtocols."""
4250 from ...extras import pd , np
@@ -61,6 +69,7 @@ def data_frame_to_list_of_points(data_frame, point_settings, **kwargs):
6169
6270 tags = []
6371 fields = []
72+ fields_indexes = []
6473 keys = []
6574
6675 if point_settings .defaultTags :
@@ -73,14 +82,18 @@ def data_frame_to_list_of_points(data_frame, point_settings, **kwargs):
7382 keys .append (key .translate (_ESCAPE_KEY ))
7483 key_format = f'{{keys[{ index } ]}}'
7584
85+ index_value = index + 1
7686 if key in data_frame_tag_columns :
77- tags .append ({'key' : key , 'value' : f"{ key_format } ={{str(p[{ index + 1 } ]).translate(_ESCAPE_KEY)}}" })
87+ tags .append ({'key' : key , 'value' : f"{ key_format } ={{str(p[{ index_value } ]).translate(_ESCAPE_KEY)}}" })
7888 elif issubclass (value .type , np .integer ):
79- fields .append (f"{ key_format } ={{p[{ index + 1 } ]}}i" )
89+ fields .append (f"{ key_format } ={{p[{ index_value } ]}}i" )
90+ fields_indexes .append (index_value )
8091 elif issubclass (value .type , (np .float , np .bool_ )):
81- fields .append (f"{ key_format } ={{p[{ index + 1 } ]}}" )
92+ fields .append (f"{ key_format } ={{p[{ index_value } ]}}" )
93+ fields_indexes .append (index_value )
8294 else :
83- fields .append (f"{ key_format } =\" {{str(p[{ index + 1 } ]).translate(_ESCAPE_STRING)}}\" " )
95+ fields .append (f"{ key_format } =\" {{str(p[{ index_value } ]).translate(_ESCAPE_STRING)}}\" " )
96+ fields_indexes .append (index_value )
8497
8598 tags .sort (key = lambda x : x ['key' ])
8699 tags = ',' .join (map (lambda y : y ['value' ], tags ))
@@ -100,7 +113,7 @@ def data_frame_to_list_of_points(data_frame, point_settings, **kwargs):
100113 if isnull .any ():
101114 rep = _replace (data_frame )
102115 lp = (reduce (lambda a , b : re .sub (* b , a ), rep , f (p ))
103- for p in _itertuples (data_frame ))
116+ for p in filter ( lambda x : _any_not_nan ( x , fields_indexes ), _itertuples (data_frame ) ))
104117 return list (lp )
105118 else :
106119 return list (map (f , _itertuples (data_frame )))
0 commit comments