diff --git a/.travis.yml b/.travis.yml index 7061ba7f..f4159d78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: python python: -# - "2.7" - "3.6" # command to install dependencies install: - pip install -r requirements.txt + - pip install -r extra-requirements.txt - pip install -r test-requirements.txt # command to run tests script: diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d16f6a9..ea740e74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ ### API 1. [#42](https://github.com/influxdata/influxdb-client-python/pull/42): Updated swagger to latest version +### Bugs +1. [#45](https://github.com/influxdata/influxdb-client-python/pull/45): Pandas is a optional dependency and has to installed separably + ## 1.1.0 [2019-11-19] ### Features diff --git a/README.rst b/README.rst index dfdb0e28..845f1591 100644 --- a/README.rst +++ b/README.rst @@ -16,10 +16,6 @@ influxdb-client-python :target: https://circleci.com/gh/influxdata/influxdb-client-python :alt: CI status -.. image:: https://img.shields.io/codecov/c/github/influxdata/influxdb-client-python.svg - :target: https://codecov.io/gh/influxdata/influxdb-client-python - :alt: Coverage - .. image:: https://img.shields.io/pypi/v/influxdb-client.svg :target: https://pypi.org/project/influxdb-client/ :alt: PyPI package @@ -375,6 +371,8 @@ Pandas DataFrame """""""""""""""" .. marker-pandas-start +.. note:: For DataFrame querying you should install Pandas dependency via ``pip install influxdb-client[extra]``. + .. note:: Note that if a query returns more then one table then the client generates a ``DataFrame`` for each of them. The ``client`` is able to retrieve data in `Pandas DataFrame `_ format thought ``query_data_frame``: diff --git a/extra-requirements.txt b/extra-requirements.txt new file mode 100644 index 00000000..ad1a0235 --- /dev/null +++ b/extra-requirements.txt @@ -0,0 +1 @@ +pandas>=0.25.3 diff --git a/influxdb_client/client/flux_csv_parser.py b/influxdb_client/client/flux_csv_parser.py index 604acbe9..924121ad 100644 --- a/influxdb_client/client/flux_csv_parser.py +++ b/influxdb_client/client/flux_csv_parser.py @@ -5,7 +5,6 @@ from typing import List import ciso8601 -from pandas import DataFrame from urllib3 import HTTPResponse from influxdb_client.client.flux_table import FluxTable, FluxColumn, FluxRecord @@ -104,7 +103,8 @@ def _parse_flux_response(self): start_new_table = False # Create DataFrame with default values if self._serialization_mode is FluxSerializationMode.dataFrame: - self._data_frame = DataFrame(data=[], columns=[], index=None) + from ..extras import pd + self._data_frame = pd.DataFrame(data=[], columns=[], index=None) for column in table.columns: self._data_frame[column.label] = column.default_value pass diff --git a/influxdb_client/client/query_api.py b/influxdb_client/client/query_api.py index 22739909..304a3398 100644 --- a/influxdb_client/client/query_api.py +++ b/influxdb_client/client/query_api.py @@ -2,8 +2,6 @@ import csv from typing import List, Generator, Any -from pandas import DataFrame - from influxdb_client import Dialect from influxdb_client import Query, QueryService 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 :param data_frame_index: the list of columns that are used as DataFrame index :return: """ + + from ..extras import pd + if org is None: org = self._influxdb_client.org @@ -115,7 +116,7 @@ def query_data_frame(self, query: str, org=None, data_frame_index: List[str] = N _dataFrames = list(_parser.generator()) if len(_dataFrames) == 0: - return DataFrame(columns=[], index=None) + return pd.DataFrame(columns=[], index=None) elif len(_dataFrames) == 1: return _dataFrames[0] else: diff --git a/influxdb_client/extras.py b/influxdb_client/extras.py new file mode 100644 index 00000000..cb0eaff7 --- /dev/null +++ b/influxdb_client/extras.py @@ -0,0 +1,6 @@ +try: + import pandas as pd +except ModuleNotFoundError as err: + raise ImportError(f"`query_data_frame` requires Pandas which couldn't be imported due: {err}") + +__all__ = ['pd'] diff --git a/requirements.txt b/requirements.txt index e11b7900..1cd82e90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,3 @@ setuptools >= 21.0.0 urllib3 >= 1.15.1 ciso8601>=2.1.1 pytz>=2019.1 -pandas>=0.25.3 \ No newline at end of file diff --git a/scripts/ci-test.sh b/scripts/ci-test.sh index 0dccef17..790ea00d 100755 --- a/scripts/ci-test.sh +++ b/scripts/ci-test.sh @@ -7,6 +7,7 @@ set -e # python --version pip install -r requirements.txt +pip install -r extra-requirements.txt pip install -r test-requirements.txt pip install pytest pytest-cov pip install twine diff --git a/setup.py b/setup.py index 058191cf..5cd57fd3 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,9 @@ with open('test-requirements.txt', 'r') as f: test_requires = [x.strip() for x in f if x.strip()] +with open('extra-requirements.txt', 'r') as f: + extra_requires = [x.strip() for x in f if x.strip()] + with open('README.rst', 'r') as f: readme = f.read() @@ -29,6 +32,7 @@ keywords=["InfluxDB", "InfluxDB Python Client"], tests_require=test_requires, install_requires=requires, + extras_require={'extra': extra_requires}, long_description_content_type="text/x-rst", packages=find_packages(), test_suite='tests', diff --git a/test-requirements.txt b/test-requirements.txt index cc6e72ce..60bd283d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,5 +6,3 @@ randomize>=0.13 pytest>=5.0.0 httpretty>=0.9.6 psutil>=5.6.3 -pandas>=0.25.3 -