Cannot work with nanosecond precision #527
Description
Influx is designed to work with nanosecond precision. Therefore, the timestamp is stored as a 64 bit unsigned Integer internally (And system max time is kind of Long.MAX in terms of Java speak).
Python, as we know, has no nanosecond support for it's datetime
objects.
Numpy's datetime64, on the other side, works nicely with nanosecond precision date objects.
If I now create a dataframe like this:
value
time
1970-01-01 00:00:00.000000001 40
2017-06-01 00:00:00.000000000 100
2017-06-10 13:13:13.123456789 150
and call within the DataFrameClient _convert_dataframe_to_lines
, I'll end up with
['myMeasurement value=40i 1', 'myMeasurement value=100i -432406528', 'myMeasurement value=150i 501012992']
See how the timestamp is correct only for the first entry.
Another bug appears when using json format instead:
[{'measurement': 'myMeasurement', 'tags': {}, 'fields': {'value': 40}, 'time': 1}, {'measurement': 'myMeasurement', 'tags': {}, 'fields': {'value': 100}, 'time': 1496275200000000000}, {'measurement': 'myMeasurement', 'tags': {}, 'fields': {'value': 150}, 'time': 1497100393123456768}]
See how for the last value, the last nanosecond precision is truncated.
In order to write data via DataFrameClient, I sadly have to use a python datetime format and cannot go for an int or something as time column directly due to type checks.
In InfluxDBClient docu for write_points, you write that :param time_precision: Either 's', 'm', 'ms' or 'u', defaults to None
even though in the code, you also allow for n
.
I didn't test out the InfluxDBClient directly for writing, but for a short glance on the code (looking at _convert_timestamp
, especially at ns = (timestamp - EPOCH).total_seconds() * 1e9
, it doesn't look like it is supporting nanosecond or even something more than second precision either.
EDIT Just to let you know, I have used influxdb==4.1.1 in my requirements.txt file and I'm running the code with Python 3.6.