Skip to content

Pandas is a optional dependency #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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