influxdb-python icon indicating copy to clipboard operation
influxdb-python copied to clipboard

Nanoseconds ignored when writing Points with RFC string format

Open fcoetzee opened this issue 5 years ago • 3 comments

Note that in the file client/write/point.py the ciso8601 library is used to convert timestamp strings to datetime.datetime objects,

However, the datetime.datetime format returned no longer supports nano-seconds, it ignores everything past microseconds

In [181]: ciso8601.parse_datetime('1996-02-25T21:20:00.001001231Z') Out[181]: datetime.datetime(1996, 2, 25, 21, 20, 0, 1001, tzinfo=datetime.timezone.utc)

Since nano-seconds are the default write precision for the DataBase, this is a major failure

No simple solution here -- the datetime libraries use dto support nanosecs, but in a streak of purism were changed to be POSIX compliant (and posix only talked about microseconds).

fcoetzee avatar Jun 02 '20 17:06 fcoetzee

@fcoetzee thanks for the issue. Does https://github.com/influxdata/influxdb-client-python suffer the same issue?

russorat avatar Jun 26 '20 22:06 russorat

Yup. Problem is here in file

influxdb-client-python-master/influxdb_client/client/write/point.py

image

fcoetzee avatar Jun 27 '20 01:06 fcoetzee

Hi @fcoetzee,

As you mentioned the datetime has a precision to microseconds and also almost all time libraries are without supports of nanoseconds:

We will have to use something like pandas timestamp:

>>> import pandas as pd
>>> pd.to_datetime('1996-02-25T21:20:00.001001231Z', unit='ns')
Timestamp('1996-02-25 21:20:00.001001231+0000', tz='UTC')

Regards

bednar avatar Jul 08 '20 04:07 bednar