Compare commits

...

10 Commits

Author SHA1 Message Date
kennethreitz edbb16ec97 next version 2017-09-01 15:37:00 -04:00
kennethreitz dec5cea722 Merge pull request #307 from audiolion/make-pandas-optional
Make pandas optional
2017-09-01 13:49:44 -04:00
Ryan Castner 38183938dc Change how travis installs to get all test dependencies 2017-09-01 13:33:28 -04:00
Ryan Castner 7f1db4023f Raise NotImplementedError if pandas is not installed 2017-09-01 13:21:21 -04:00
Ryan Castner b09fface1b Make pandas an optional install 2017-09-01 13:20:54 -04:00
kennethreitz 69edb9def3 Update index.rst 2017-08-28 01:14:36 -04:00
kennethreitz ec54918f4a Update tutorial.rst 2017-08-28 01:06:43 -04:00
kennethreitz ab6633549f Update index.rst 2017-08-28 01:04:16 -04:00
kennethreitz 56005d8022 Update README.rst 2017-08-28 01:02:49 -04:00
kennethreitz 36fa7ef097 update docs
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
2017-08-27 03:56:14 -04:00
8 changed files with 42 additions and 24 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
+6 -6
View File
@@ -87,7 +87,7 @@ JSON!
+++++
::
>>> print(data.json)
>>> print(data.export('json'))
[
{
"last_name": "Adams",
@@ -106,7 +106,7 @@ YAML!
+++++
::
>>> print(data.yaml)
>>> print(data.export('yaml'))
- {age: 90, first_name: John, last_name: Adams}
- {age: 83, first_name: Henry, last_name: Ford}
@@ -114,7 +114,7 @@ CSV...
++++++
::
>>> print(data.csv)
>>> print(data.export('csv'))
first_name,last_name,age
John,Adams,90
Henry,Ford,83
@@ -124,20 +124,20 @@ EXCEL!
::
>>> with open('people.xls', 'wb') as f:
... f.write(data.xls)
... f.write(data.export('xls'))
DBF!
++++
::
>>> with open('people.dbf', 'wb') as f:
... f.write(data.dbf)
... f.write(data.export('dbf'))
Pandas DataFrame!
+++++++++++++++++
::
>>> print(data.df):
>>> print(data.export('df')):
first_name last_name age
0 John Adams 90
1 Henry Ford 83
+4 -4
View File
@@ -31,17 +31,17 @@ Tablib is an :ref:`MIT Licensed <mit>` format-agnostic tabular dataset library,
... data.append(i)
>>> print(data.json)
>>> print(data.export('json'))
[{"Last Name": "Reitz", "First Name": "Kenneth", "Age": 22}, {"Last Name": "Monke", "First Name": "Bessie", "Age": 21}]
>>> print(data.yaml)
>>> print(data.export('yaml'))
- {Age: 22, First Name: Kenneth, Last Name: Reitz}
- {Age: 21, First Name: Bessie, Last Name: Monke}
>>> data.xlsx
>>> data.export('xlsx')
<censored binary data>
>>> data.df
>>> data.export('df')
First Name Last Name Age
0 Kenneth Reitz 22
1 Bessie Monke 21
+1 -2
View File
@@ -49,7 +49,7 @@ Tablib is released under terms of `The MIT License`_.
Tablib License
--------------
Copyright 2016 Kenneth Reitz
Copyright 2017 Kenneth Reitz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -77,7 +77,6 @@ Pythons Supported
At this time, the following Python platforms are officially supported:
* cPython 2.6
* cPython 2.7
* cPython 3.3
* cPython 3.4
+15 -7
View File
@@ -115,30 +115,38 @@ Tablib's killer feature is the ability to export your :class:`Dataset` objects i
**Comma-Separated Values** ::
>>> data.csv
>>> data.export('csv')
Last Name,First Name,Age
Reitz,Kenneth,22
Monke,Bessie,20
**JavaScript Object Notation** ::
>>> data.json
>>> data.export('json')
[{"Last Name": "Reitz", "First Name": "Kenneth", "Age": 22}, {"Last Name": "Monke", "First Name": "Bessie", "Age": 20}]
**YAML Ain't Markup Language** ::
>>> data.yaml
>>> data.export('yaml')
- {Age: 22, First Name: Kenneth, Last Name: Reitz}
- {Age: 20, First Name: Bessie, Last Name: Monke}
**Microsoft Excel** ::
>>> data.xls
>>> data.export('xls')
<censored binary data>
**Pandas DataFrame** ::
>>> data.export('df')
First Name Last Name Age
0 Kenneth Reitz 22
1 Bessie Monke 21
------------------------
Selecting Rows & Columns
------------------------
@@ -216,7 +224,7 @@ Let's add a dynamic column to our :class:`Dataset` object. In this example, we h
Let's have a look at our data. ::
>>> data.yaml
>>> data.export('yaml')
- {Age: 22, First Name: Kenneth, Grade: 0.6, Last Name: Reitz}
- {Age: 20, First Name: Bessie, Grade: 0.75, Last Name: Monke}
@@ -246,7 +254,7 @@ For example, we can use the data available in the row to guess the gender of a s
Adding this function to our dataset as a dynamic column would result in: ::
>>> data.yaml
>>> data.export('yaml')
- {Age: 22, First Name: Kenneth, Gender: Male, Last Name: Reitz}
- {Age: 20, First Name: Bessie, Gender: Female, Last Name: Monke}
@@ -346,7 +354,7 @@ When, it's often useful to create a blank row containing information on the upco
# Write spreadsheet to disk
with open('grades.xls', 'wb') as f:
f.write(tests.xls)
f.write(tests.export('xls'))
The resulting **tests.xls** will have the following layout:
+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'],
},
)
+2 -2
View File
@@ -18,8 +18,8 @@ from tablib.compat import OrderedDict, unicode
__title__ = 'tablib'
__version__ = '0.12.0'
__build__ = 0x001200
__version__ = '0.12.1'
__build__ = 0x001201
__author__ = 'Kenneth Reitz'
__license__ = 'MIT'
__copyright__ = 'Copyright 2017 Kenneth Reitz'
+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