influxdata / influxdb-python

Python client for InfluxDB
MIT License
1.7k stars 521 forks source link

Nanoseconds ignored when writing Points with RFC string format #829

Open fcoetzee opened 4 years ago

fcoetzee commented 4 years ago

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).

russorat commented 4 years ago

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

fcoetzee commented 4 years ago

Yup. Problem is here in file

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

image

bednar commented 4 years ago

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