I want to use Epoch dates with second precision as timestamps in an InfluxDB2 database.
I am using the influxdb_client write_api to write a pandas dataframe.
When I examine the bucket that results from the write it seems that the timestamps are not accurate.
For example, here are six Epoch dates that I have used with the corresponding dates in readable format and then timestamps as reflected in the bucket when I explore the data
Epoch date Human-readable date (GMT) Influx _time
1614525576 2021-02-28 15:19:36 2021-02-28T16:11:40.564Z
1614520964 2021-02-28 14:02:44 2021-02-28T16:11:40.564Z
1614464526 2021-02-27 22:22:06 2021-02-27T23:55:40.556Z
1614276361 2021-02-25 18:06:01 2021-02-25T19:03:40.53Z
1609688700 2021-01-03 15:45:00 2021-01-03T18:11:39.904Z
1609682156 2021-01-03 13:55:56 2021-01-03T14:07:39.902Z
Here is the code I used to write the data to Influx with token, org and bucket strings redacted:
import pandas as pd
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
token = "redacted"
org = "redacted"
bucket = "redacted"
data = [[1614525576, 'Running', 3], [1614520964, 'Cycling', 30], [1614464526, 'Running', 2], [1614276361, 'Cycling', 20], [1609688700, 'Running', 1], [1609682156, 'Cycling', 10]]
df = pd.DataFrame(data, columns = ['Date', 'Activity', 'Distance'])
df.set_index('Date', inplace=True)
client = InfluxDBClient(url="influxdb.itinker.net:8086", token=token, org=org)
write_api = client.write_api(write_options=SYNCHRONOUS)
write_api.write(bucket, org, df, data_frame_measurement_name='exercise', data_frame_tag_columns=['Activity'], write_precision='s')
write_api.close()
client.close()
print(df)
print(df.dtypes)
And here is the output from running the script
Activity Distance
Date
1614525576 Running 3
1614520964 Cycling 30
1614464526 Running 2
1614276361 Cycling 20
1609688700 Running 1
1609682156 Cycling 10
Activity object
Distance int64
dtype: object
Why is there a discrepancy between the Influx timestamp and the date I would expect from the Epoch dates I supplied?