Skip to content

Commit

Permalink
Pandas is optional dependency (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Nov 29, 2019
1 parent 709b3eb commit 353b688
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html>`_ format thought ``query_data_frame``:
Expand Down
1 change: 1 addition & 0 deletions extra-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pandas>=0.25.3
4 changes: 2 additions & 2 deletions influxdb_client/client/flux_csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions influxdb_client/client/query_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions influxdb_client/extras.py
Original file line number Diff line number Diff line change
@@ -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']
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ setuptools >= 21.0.0
urllib3 >= 1.15.1
ciso8601>=2.1.1
pytz>=2019.1
pandas>=0.25.3
1 change: 1 addition & 0 deletions scripts/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ randomize>=0.13
pytest>=5.0.0
httpretty>=0.9.6
psutil>=5.6.3
pandas>=0.25.3

0 comments on commit 353b688

Please sign in to comment.