7
7
8
8
from .client import InfluxDBClient
9
9
10
+ try :
11
+ import pandas as pd
12
+ except ImportError as ex :
13
+ raise ImportError ('DataFrameClient requires Pandas, '
14
+ '"{ex}" problem importing' .format (ex = str (ex )))
15
+ try :
16
+ import numpy as np
17
+ except ImportError as ex :
18
+ raise ImportError ('DataFrameClient requires Numpy, '
19
+ '"{ex}" problem importing' .format (ex = str (ex )))
20
+
10
21
11
22
class DataFrameClient (InfluxDBClient ):
12
23
"""
@@ -17,22 +28,6 @@ class DataFrameClient(InfluxDBClient):
17
28
18
29
def __init__ (self , ignore_nan = True , * args , ** kwargs ):
19
30
super (DataFrameClient , self ).__init__ (* args , ** kwargs )
20
- try :
21
- global pd
22
- import pandas as pd
23
- except ImportError as ex :
24
- raise ImportError (
25
- 'DataFrameClient requires Pandas, "{ex}" problem importing'
26
- .format (ex = str (ex ))
27
- )
28
- try :
29
- global np
30
- import numpy as np
31
- except ImportError as ex :
32
- raise ImportError (
33
- 'DataFrameClient requires Numpy, "{ex}" problem importing'
34
- .format (ex = str (ex ))
35
- )
36
31
37
32
self .EPOCH = pd .Timestamp ('1970-01-01 00:00:00.000+00:00' )
38
33
self .ignore_nan = ignore_nan
@@ -149,7 +144,8 @@ def _convert_dataframe_to_json(self, dataframe, name, time_precision='s'):
149
144
150
145
def _convert_array (self , array ):
151
146
if self .ignore_nan :
152
- condition = (all (isinstance (el , (int , float , np .number )) for el in array ) and
147
+ number_types = (int , float , np .number )
148
+ condition = (all (isinstance (el , number_types ) for el in array ) and
153
149
np .isnan (array ))
154
150
return list (np .where (condition , None , array ))
155
151
else :
0 commit comments