@@ -132,7 +132,7 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION
132132 keys = []
133133 # tags holds a list of tag f-string segments ordered alphabetically by tag key.
134134 tags = []
135- # fields holds a list of field f-string segments ordered alphebetically by field key
135+ # fields holds a list of field f-string segments ordered alphabetically by field key
136136 fields = []
137137 # field_indexes holds the index into each row of all the fields.
138138 field_indexes = []
@@ -160,6 +160,11 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION
160160 # null_columns has a bool value for each column holding
161161 # whether that column contains any null (NaN or None) values.
162162 null_columns = data_frame .isnull ().any ()
163+
164+ # inf_columns has a bool value for each column holding
165+ # whether that column contains any Inf values.
166+ inf_columns = data_frame .isin ([np .inf , - np .inf ]).any ()
167+
163168 timestamp_index = 0
164169
165170 # Iterate through the columns building up the expression for each column.
@@ -175,9 +180,10 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION
175180
176181 if key in data_frame_tag_columns :
177182 # This column is a tag column.
178- if null_columns .iloc [index ]:
183+ if null_columns .iloc [index ] or inf_columns . iloc [ index ] :
179184 key_value = f"""{{
180- '' if { val_format } == '' or pd.isna({ val_format } ) else
185+ '' if { val_format } == '' or pd.isna({ val_format } ) or
186+ ({ inf_columns .iloc [index ]} and np.isinf({ val_format } )) else
181187 f',{ key_format } ={{str({ val_format } ).translate(_ESCAPE_STRING)}}'
182188 }}"""
183189 else :
@@ -199,16 +205,17 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION
199205 if (issubclass (value .type , np .integer ) or issubclass (value .type , np .floating ) or
200206 issubclass (value .type , np .bool_ )):
201207 suffix = 'i' if issubclass (value .type , np .integer ) else ''
202- if null_columns .iloc [index ]:
208+ if null_columns .iloc [index ] or inf_columns . iloc [ index ] :
203209 field_value = (
204- f"""{{"" if pd.isna({ val_format } ) else f"{ sep } { key_format } ={{{ val_format } }}{ suffix } "}}"""
210+ f"""{{"" if pd.isna({ val_format } ) or ({ inf_columns .iloc [index ]} and np.isinf({ val_format } )) else
211+ f"{ sep } { key_format } ={{{ val_format } }}{ suffix } "}}"""
205212 )
206213 else :
207214 field_value = f'{ sep } { key_format } ={{{ val_format } }}{ suffix } '
208215 else :
209- if null_columns .iloc [index ]:
216+ if null_columns .iloc [index ] or inf_columns . iloc [ index ] :
210217 field_value = f"""{{
211- '' if pd.isna({ val_format } ) else
218+ '' if pd.isna({ val_format } ) or ( { inf_columns . iloc [ index ] } and np.isinf( { val_format } )) else
212219 f'{ sep } { key_format } ="{{str({ val_format } ).translate(_ESCAPE_STRING)}}"'
213220 }}"""
214221 else :
@@ -234,11 +241,12 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION
234241 '_ESCAPE_STRING' : _ESCAPE_STRING ,
235242 'keys' : keys ,
236243 'pd' : pd ,
244+ 'np' : np ,
237245 })
238246
239247 for k , v in dict (data_frame .dtypes ).items ():
240248 if k in data_frame_tag_columns :
241- data_frame [k ]. replace ( '' , np .nan , inplace = True )
249+ data_frame [k ] = data_frame [ k ]. apply ( lambda x : np .nan if x == '' else x )
242250
243251 self .data_frame = data_frame
244252 self .f = f
0 commit comments