From 51965fe2f7ee698f825291964f8c6f5f3e0f2d5e Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Wed, 10 Nov 2021 11:20:46 +0100 Subject: [PATCH] fix: regexp for remove leading comma for NaN values --- influxdb_client/client/write/dataframe_serializer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/influxdb_client/client/write/dataframe_serializer.py b/influxdb_client/client/write/dataframe_serializer.py index 249735cb..4d83e8d4 100644 --- a/influxdb_client/client/write/dataframe_serializer.py +++ b/influxdb_client/client/write/dataframe_serializer.py @@ -160,9 +160,9 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION # This column is a tag column. if null_columns[index]: key_value = f"""{{ - '{_EMPTY_EXPRESSION}' if {val_format} == '' or type({val_format}) == float and math.isnan({val_format}) else + '' if {val_format} == '' or type({val_format}) == float and math.isnan({val_format}) else f',{key_format}={{str({val_format}).translate(_ESCAPE_STRING)}}' - }}""" # noqa: E501 + }}""" else: key_value = f',{key_format}={{str({val_format}).translate(_ESCAPE_KEY)}}' tags.append(key_value) @@ -181,14 +181,14 @@ def __init__(self, data_frame, point_settings, precision=DEFAULT_WRITE_PRECISION elif issubclass(value.type, np.floating): if null_columns[index]: field_value = f"""{{ - "{_EMPTY_EXPRESSION}" if math.isnan({val_format}) else f"{sep}{key_format}={{{val_format}}}" + "{sep}{_EMPTY_EXPRESSION}" if math.isnan({val_format}) else f"{sep}{key_format}={{{val_format}}}" }}""" else: field_value = f'{sep}{key_format}={{{val_format}}}' else: if null_columns[index]: field_value = f"""{{ - '{_EMPTY_EXPRESSION}' if type({val_format}) == float and math.isnan({val_format}) else + '{sep}{_EMPTY_EXPRESSION}' if type({val_format}) == float and math.isnan({val_format}) else f'{sep}{key_format}="{{str({val_format}).translate(_ESCAPE_STRING)}}"' }}""" else: @@ -249,7 +249,7 @@ def serialize(self, chunk_idx: int = None): if self.first_field_maybe_null: # When the first field is null (None/NaN), we'll have # a spurious leading comma which needs to be removed. - lp = (re.sub(f"{_EMPTY_EXPRESSION},|{_EMPTY_EXPRESSION}", '', self.f(p)) + lp = (re.sub(f",{_EMPTY_EXPRESSION}|{_EMPTY_EXPRESSION},|{_EMPTY_EXPRESSION}", '', self.f(p)) for p in filter(lambda x: _any_not_nan(x, self.field_indexes), _itertuples(chunk))) return list(lp) else: