@@ -37,6 +37,14 @@ def _itertuples(data_frame):
37
37
return zip (data_frame .index , * cols )
38
38
39
39
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
+
40
48
def data_frame_to_list_of_points (data_frame , point_settings , ** kwargs ):
41
49
"""Serialize DataFrame into LineProtocols."""
42
50
from ...extras import pd , np
@@ -61,6 +69,7 @@ def data_frame_to_list_of_points(data_frame, point_settings, **kwargs):
61
69
62
70
tags = []
63
71
fields = []
72
+ fields_indexes = []
64
73
keys = []
65
74
66
75
if point_settings .defaultTags :
@@ -73,14 +82,18 @@ def data_frame_to_list_of_points(data_frame, point_settings, **kwargs):
73
82
keys .append (key .translate (_ESCAPE_KEY ))
74
83
key_format = f'{{keys[{ index } ]}}'
75
84
85
+ index_value = index + 1
76
86
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)}}" })
78
88
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 )
80
91
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 )
82
94
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 )
84
97
85
98
tags .sort (key = lambda x : x ['key' ])
86
99
tags = ',' .join (map (lambda y : y ['value' ], tags ))
@@ -100,7 +113,7 @@ def data_frame_to_list_of_points(data_frame, point_settings, **kwargs):
100
113
if isnull .any ():
101
114
rep = _replace (data_frame )
102
115
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 ) ))
104
117
return list (lp )
105
118
else :
106
119
return list (map (f , _itertuples (data_frame )))
0 commit comments