Skip to content

Commit ad411de

Browse files
committed
fix: add Pandas as optional dependency (#43)
1 parent 709b3eb commit ad411de

File tree

9 files changed

+20
-12
lines changed

9 files changed

+20
-12
lines changed

README.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ influxdb-client-python
1616
:target: https://circleci.com/gh/influxdata/influxdb-client-python
1717
:alt: CI status
1818

19-
.. image:: https://img.shields.io/codecov/c/github/influxdata/influxdb-client-python.svg
20-
:target: https://codecov.io/gh/influxdata/influxdb-client-python
21-
:alt: Coverage
22-
2319
.. image:: https://img.shields.io/pypi/v/influxdb-client.svg
2420
:target: https://pypi.org/project/influxdb-client/
2521
:alt: PyPI package
@@ -375,6 +371,8 @@ Pandas DataFrame
375371
""""""""""""""""
376372
.. marker-pandas-start
377373
374+
.. note:: For DataFrame querying you should install Pandas dependency via ``pip install influxdb-client[extra]``.
375+
378376
.. note:: Note that if a query returns more then one table then the client generates a ``DataFrame`` for each of them.
379377

380378
The ``client`` is able to retrieve data in `Pandas DataFrame <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html>`_ format thought ``query_data_frame``:

extra-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pandas>=0.25.3

influxdb_client/client/flux_csv_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import List
66

77
import ciso8601
8-
from pandas import DataFrame
98
from urllib3 import HTTPResponse
109

1110
from influxdb_client.client.flux_table import FluxTable, FluxColumn, FluxRecord
@@ -104,7 +103,8 @@ def _parse_flux_response(self):
104103
start_new_table = False
105104
# Create DataFrame with default values
106105
if self._serialization_mode is FluxSerializationMode.dataFrame:
107-
self._data_frame = DataFrame(data=[], columns=[], index=None)
106+
from ..extras import pd
107+
self._data_frame = pd.DataFrame(data=[], columns=[], index=None)
108108
for column in table.columns:
109109
self._data_frame[column.label] = column.default_value
110110
pass

influxdb_client/client/query_api.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import csv
33
from typing import List, Generator, Any
44

5-
from pandas import DataFrame
6-
75
from influxdb_client import Dialect
86
from influxdb_client import Query, QueryService
97
from influxdb_client.client.flux_csv_parser import FluxCsvParser, FluxSerializationMode
@@ -104,6 +102,9 @@ def query_data_frame(self, query: str, org=None, data_frame_index: List[str] = N
104102
:param data_frame_index: the list of columns that are used as DataFrame index
105103
:return:
106104
"""
105+
106+
from ..extras import pd
107+
107108
if org is None:
108109
org = self._influxdb_client.org
109110

@@ -115,7 +116,7 @@ def query_data_frame(self, query: str, org=None, data_frame_index: List[str] = N
115116
_dataFrames = list(_parser.generator())
116117

117118
if len(_dataFrames) == 0:
118-
return DataFrame(columns=[], index=None)
119+
return pd.DataFrame(columns=[], index=None)
119120
elif len(_dataFrames) == 1:
120121
return _dataFrames[0]
121122
else:

influxdb_client/extras.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
try:
2+
import pandas as pd
3+
except ModuleNotFoundError as err:
4+
raise ImportError(f"`query_data_frame` requires Pandas which couldn't be imported due: {err}")
5+
6+
__all__ = ['pd']

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ setuptools >= 21.0.0
66
urllib3 >= 1.15.1
77
ciso8601>=2.1.1
88
pytz>=2019.1
9-
pandas>=0.25.3

scripts/ci-test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -e
77
#
88
python --version
99
pip install -r requirements.txt
10+
pip install -r extra-requirements.txt
1011
pip install -r test-requirements.txt
1112
pip install pytest pytest-cov
1213
pip install twine

setup.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
with open('test-requirements.txt', 'r') as f:
1111
test_requires = [x.strip() for x in f if x.strip()]
1212

13+
with open('extra-requirements.txt', 'r') as f:
14+
extra_requires = [x.strip() for x in f if x.strip()]
15+
1316
with open('README.rst', 'r') as f:
1417
readme = f.read()
1518

@@ -29,6 +32,7 @@
2932
keywords=["InfluxDB", "InfluxDB Python Client"],
3033
tests_require=test_requires,
3134
install_requires=requires,
35+
extras_require={'extra': extra_requires},
3236
long_description_content_type="text/x-rst",
3337
packages=find_packages(),
3438
test_suite='tests',

test-requirements.txt

-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ randomize>=0.13
66
pytest>=5.0.0
77
httpretty>=0.9.6
88
psutil>=5.6.3
9-
pandas>=0.25.3
10-

0 commit comments

Comments
 (0)