Merge pull request #307 from audiolion/make-pandas-optional

Make pandas optional
This commit is contained in:
2017-09-01 13:49:44 -04:00
committed by GitHub
3 changed files with 14 additions and 3 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ python:
- 3.5
- 3.6
install:
- python setup.py install
- pip install -r requirements.txt
script: python test_tablib.py
+3 -1
View File
@@ -48,7 +48,6 @@ install = [
'xlrd',
'xlwt',
'pyyaml',
'pandas'
]
@@ -81,4 +80,7 @@ setup(
],
tests_require=['pytest'],
install_requires=install,
extras_require={
'pandas': ['pandas'],
},
)
+10 -1
View File
@@ -10,7 +10,10 @@ if sys.version_info[0] > 2:
else:
from cStringIO import StringIO as BytesIO
from pandas import DataFrame
try:
from pandas import DataFrame
except ImportError:
DataFrame = None
import tablib
@@ -21,6 +24,8 @@ extensions = ('df', )
def detect(stream):
"""Returns True if given stream is a DataFrame."""
if DataFrame is None:
return False
try:
DataFrame(stream)
return True
@@ -30,6 +35,10 @@ def detect(stream):
def export_set(dset, index=None):
"""Returns DataFrame representation of DataBook."""
if DataFrame is None:
raise NotImplementedError(
'DataFrame Format requires `pandas` to be installed.'
' Try `pip install tablib[pandas]`.')
dataframe = DataFrame(dset.dict, columns=dset.headers)
return dataframe