Open supriyopaul opened 6 years ago
did you get to solve the issues ? thanks
@ayoube01 after a while I realized InfluxDBClient is doing the expected thing. It conveys python datatypes to influxDB without any intelligent decision making of assumptions.
@ayoube01 @supriyopaul the temporary solution I used to convert int to float:
def df_int_to_float(df):
for i in df.select_dtypes('int').columns.values:
df[i] = df[i].astype(float)
return df
df = self.df_int_to_float(df)
@tux-00 Thanks, I too did the same.
If you assume all numerical field values are floats, try following code. It uses monkey patch to remove + "i" code when type is integer.
import influxdb
from influxdb import InfluxDBClient
from influxdb.line_protocol import _get_unicode, quote_ident, _is_float, text_type
class MyInfluxDBClient(InfluxDBClient):
def __init__(self, host='localhost', port=8086, username='root', password='root', database=None, ssl=False,
verify_ssl=False, timeout=None, retries=3, use_udp=False, udp_port=4444, proxies=None, pool_size=10,
path=''):
super().__init__(host, port, username, password, database, ssl, verify_ssl, timeout, retries, use_udp, udp_port,
proxies, pool_size, path)
# monkey patch, no integer
def _escape_value(value):
value = _get_unicode(value)
if isinstance(value, text_type) and value != '':
return quote_ident(value)
elif _is_float(value):
return repr(value)
return str(value)
influxdb.line_protocol._escape_value = _escape_value
In the end, shouldn't the Python module do the conversion itself?
I mean, if by default InfluxDB considers all int
values to be float
(unless told explicitely with the "i" character placed after the int
value), then why both InfluxDbClient
and its subclasses do not enforce this rule automatically by converting values like @tux-00 suggested?
According to influxdb doc : " by default, InfluxDB assumes all numerical field values are floats."
But InfluxDBClient module for python: It does not do the same.
Now the concern is what if the programs change the data-types while using the InfluxdbClient? Points won't get written into database...