influxdata / influxdb-python

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

timestamp rounding error dataframe client #885

Open svhb1000 opened 3 years ago

svhb1000 commented 3 years ago

As continuation of #811 The solution for the rounding error seems not to be merged.

This gives particular problems when merging data from different sources to a database : timestamps must be CORRECT! This is an essential point in a timeseries database. (my thoughts...)

python 3 makes floats if you divide with '/' --> please change to '//'

Example : line 375 fro _dataframe_client.py

            time = ((dataframe.index.to_timestamp().values.astype(np.int64) /
                     precision_factor).astype(np.int64).astype(str))

to

            time = ((dataframe.index.to_timestamp().values.astype(np.int64) //
                     precision_factor).astype(np.int64).astype(str))
cuxcrider commented 3 years ago

@svhb1000 which version of pandas are you using? I am on 1.2.4 and using the code I posted in #811 I've been testing this without success. Even with the '//' if I have timestamps that are within a few nanoseconds of each other they are combined into one datapoint upon writing to influx.

Edit: my mistake, it is working once I change to '//'. Do you also change the line below line 375 to '//' or should that be left as a single '/'?

svhb1000 commented 3 years ago

The change is needed in both places. Everywhere the timestamp is converted to a float by the '/' in python 3