Skip to content

Commit 65ddc0f

Browse files
author
aviau
committed
Import pandas in __init__()
1 parent 6249689 commit 65ddc0f

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

influxdb/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# -*- coding: utf-8 -*-
22
from .client import InfluxDBClient
3+
from .dataframe_client import DataFrameClient
34

45

5-
__all__ = ['InfluxDBClient']
6+
__all__ = [
7+
'InfluxDBClient',
8+
'DataFrameClient',
9+
]
610

7-
try:
8-
import pandas
9-
from .dataframe_client import DataFrameClient
10-
__all__ += 'DataFrameClient'
11-
except ImportError:
12-
pass
1311

1412
__version__ = '0.1.13'

influxdb/dataframe_client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
import math
66
import warnings
7-
import pandas as pd
87

98
from .client import InfluxDBClient
109

@@ -16,7 +15,18 @@ class DataFrameClient(InfluxDBClient):
1615
The client reads and writes from pandas DataFrames.
1716
"""
1817

19-
EPOCH = pd.Timestamp('1970-01-01 00:00:00.000+00:00')
18+
def __init__(self, *args, **kwargs):
19+
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+
29+
self.EPOCH = pd.Timestamp('1970-01-01 00:00:00.000+00:00')
2030

2131
def write_points(self, data, *args, **kwargs):
2232
"""
@@ -122,7 +132,7 @@ def _convert_dataframe_to_json(self, dataframe, name, time_precision='s'):
122132
return data
123133

124134
def _datetime_to_epoch(self, datetime, time_precision='s'):
125-
seconds = (datetime - DataFrameClient.EPOCH).total_seconds()
135+
seconds = (datetime - self.EPOCH).total_seconds()
126136
if time_precision == 's':
127137
return seconds
128138
elif time_precision == 'm':
File renamed without changes.

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ deps = -r{toxinidir}/requirements.txt
2929
commands = sphinx-build -b html docs/source docs/build
3030

3131
[flake8]
32-
ignore = N802,F401
32+
ignore = N802,F821
3333
# N802: nosetests's setUp function
34-
# F401: False positive in intluxdb/__init__.py
34+
# F821: False positive in intluxdb/dataframe_client.py

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