Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 653bc1f

Browse files
committed
fix handle error when trying to import pandas
1 parent cc95370 commit 653bc1f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

examples/tutorial_pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main(host='localhost', port=8086):
2020
client.create_database(dbname)
2121

2222
print("Write DataFrame")
23-
client.write_points({'demo':df})
23+
client.write_points({'demo': df})
2424

2525
print("Read DataFrame")
2626
client.query("select * from demo")

influxdb/dataframe_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
from .client import InfluxDBClient
99

10+
try:
11+
import pandas as pd
12+
except ImportError:
13+
pd = None
14+
1015

1116
class DataFrameClient(InfluxDBClient):
1217
"""
@@ -17,13 +22,9 @@ class DataFrameClient(InfluxDBClient):
1722

1823
def __init__(self, *args, **kwargs):
1924
super(DataFrameClient, self).__init__(*args, **kwargs)
20-
try:
21-
global pd
22-
import pandas as pd
23-
except ImportError as ex:
25+
if not pd:
2426
raise ImportError(
25-
'DataFrameClient requires Pandas, "{ex}" problem importing'
26-
.format(ex=str(ex))
27+
'DataFrameClient requires Pandas'
2728
)
2829

2930
self.EPOCH = pd.Timestamp('1970-01-01 00:00:00.000+00:00')

0 commit comments

Comments
 (0)