Skip to content

Commit d7e37d6

Browse files
committed
Merge pull request influxdata#118 from areski/fix-pandas-import
handle error nicely when trying to import pandas
2 parents cc95370 + 653bc1f commit d7e37d6

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy