Skip to content

Commit 1fbd754

Browse files
committed
fix: regexp for remove leading comma for NaN values
1 parent e0abebb commit 1fbd754

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

influxdb_client/client/write/dataframe_serializer.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION
160160
# This column is a tag column.
161161
if null_columns[index]:
162162
key_value = f"""{{
163-
'{_EMPTY_EXPRESSION}' if {val_format} == '' or type({val_format}) == float and math.isnan({val_format}) else
163+
'' if {val_format} == '' or type({val_format}) == float and math.isnan({val_format}) else
164164
f',{key_format}={{str({val_format}).translate(_ESCAPE_STRING)}}'
165-
}}""" # noqa: E501
165+
}}"""
166166
else:
167167
key_value = f',{key_format}={{str({val_format}).translate(_ESCAPE_KEY)}}'
168168
tags.append(key_value)
@@ -181,14 +181,14 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION
181181
elif issubclass(value.type, np.floating):
182182
if null_columns[index]:
183183
field_value = f"""{{
184-
"{_EMPTY_EXPRESSION}" if math.isnan({val_format}) else f"{sep}{key_format}={{{val_format}}}"
184+
"{sep}{_EMPTY_EXPRESSION}" if math.isnan({val_format}) else f"{sep}{key_format}={{{val_format}}}"
185185
}}"""
186186
else:
187187
field_value = f'{sep}{key_format}={{{val_format}}}'
188188
else:
189189
if null_columns[index]:
190190
field_value = f"""{{
191-
'{_EMPTY_EXPRESSION}' if type({val_format}) == float and math.isnan({val_format}) else
191+
'{sep}{_EMPTY_EXPRESSION}' if type({val_format}) == float and math.isnan({val_format}) else
192192
f'{sep}{key_format}="{{str({val_format}).translate(_ESCAPE_STRING)}}"'
193193
}}"""
194194
else:
@@ -249,7 +249,7 @@ def serialize(self, chunk_idx: int = None):
249249
if self.first_field_maybe_null:
250250
# When the first field is null (None/NaN), we'll have
251251
# a spurious leading comma which needs to be removed.
252-
lp = (re.sub(f"{_EMPTY_EXPRESSION},|{_EMPTY_EXPRESSION}", '', self.f(p))
252+
lp = (re.sub(f",{_EMPTY_EXPRESSION}|{_EMPTY_EXPRESSION},|{_EMPTY_EXPRESSION}", '', self.f(p))
253253
for p in filter(lambda x: _any_not_nan(x, self.field_indexes), _itertuples(chunk)))
254254
return list(lp)
255255
else:

0 commit comments

Comments
 (0)