influxdata / influxdb-python

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

Precision error occur even divisor is 1 #870

Open tsogithub opened 3 years ago

tsogithub commented 3 years ago

https://github.com/influxdata/influxdb-python/blob/7b0367309b118e8be97bd85af4433b25129a4618/influxdb/_dataframe_client.py#L291

https://github.com/influxdata/influxdb-python/blob/7b0367309b118e8be97bd85af4433b25129a4618/influxdb/_dataframe_client.py#L305

https://github.com/influxdata/influxdb-python/blob/7b0367309b118e8be97bd85af4433b25129a4618/influxdb/_dataframe_client.py#L375

https://github.com/influxdata/influxdb-python/blob/7b0367309b118e8be97bd85af4433b25129a4618/influxdb/_dataframe_client.py#L378

It is numpy issue not yours. There is no need to take a division in case of 'precision_time' has set to 'n' (nano second). If division present, precision error may occur even the divisor is 1.

I advise to check 'n' is 1 to solve the issue with high readability:

[BEFORE]: time = ((pd.to_datetime(dataframe.index).values.astype(np.int64) / precision_factor).astype(np.int64).astype(str)) [AFTER]:

        if precision_factor == 1.0:
            time = ((pd.to_datetime(dataframe.index).values.astype(np.int64)).astype(str))
        else:
            time = ((pd.to_datetime(dataframe.index).values.astype(np.int64) /
                    precision_factor).astype(np.int64).astype(str))