Skip to content

Commit 06fc5c1

Browse files
authored
Merge branch 'master' into readme-formatting
2 parents bb7adff + 34dec68 commit 06fc5c1

16 files changed

+1365
-326
lines changed

.circleci/config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ jobs:
4545
. venv/bin/activate
4646
tox -e py38-extra
4747
48-
- run:
49-
name: run linting
50-
command: |
51-
. venv/bin/activate
52-
tox -e lint
53-
5448
- store_artifacts:
5549
path: test-reports
5650
destination: test-reports

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/python/black
3-
rev: 19.3b0
3+
rev: 22.3.0
44
hooks:
55
- id: black
66
args: [--safe]

CHANGELOG

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
- 0.8.10: Future version
1+
- 0.8.11: Future version. Drop support for Python 2.7, 3.5, 3.6. New formats. Improve column width options.
2+
- 0.8.10: Python 3.10 support. Bug fixes. Column width parameter.
23
- 0.8.9: Bug fix. Revert support of decimal separators.
34
- 0.8.8: Python 3.9 support, 3.10 ready.
45
New formats: ``unsafehtml``, ``latex_longtable``, ``fancy_outline``.
@@ -11,7 +12,7 @@
1112
- 0.8.6: Bug fixes. Stop supporting Python 3.3, 3.4.
1213
- 0.8.5: Fix broken Windows package. Minor documentation updates.
1314
- 0.8.4: Bug fixes.
14-
- 0.8.3: New formats: `github`. Custom colum alignment. Bug fixes.
15+
- 0.8.3: New formats: `github`. Custom column alignment. Bug fixes.
1516
- 0.8.2: Bug fixes.
1617
- 0.8.1: Multiline data in several output formats.
1718
New ``latex_raw`` format.

README.md

Lines changed: 132 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ pip install tabulate
2525

2626
The command line utility will be installed as `tabulate` to `bin` on
2727
Linux (e.g. `/usr/bin`); or as `tabulate.exe` to `Scripts` in your
28-
Python installation on Windows (e.g.
29-
`C:\Python39\Scripts\tabulate.exe`).
28+
Python installation on Windows (e.g. `C:\Python39\Scripts\tabulate.exe`).
3029

3130
You may consider installing the library only for the current user:
3231

@@ -82,6 +81,7 @@ The following tabular data types are supported:
8281
- list of lists or another iterable of iterables
8382
- list or another iterable of dicts (keys as columns)
8483
- dict of iterables (keys as columns)
84+
- list of dataclasses (Python 3.7+ only, field names as columns)
8585
- two-dimensional NumPy array
8686
- NumPy record arrays (names as columns)
8787
- pandas.DataFrame
@@ -155,7 +155,15 @@ Supported table formats are:
155155
- "simple"
156156
- "github"
157157
- "grid"
158+
- "simple\_grid"
159+
- "rounded\_grid"
160+
- "double\_grid"
158161
- "fancy\_grid"
162+
- "outline"
163+
- "simple\_outline"
164+
- "rounded\_outline"
165+
- "double\_outline"
166+
- "fancy\_outline"
159167
- "pipe"
160168
- "orgtbl"
161169
- "jira"
@@ -229,7 +237,47 @@ corresponds to the `pipe` format without alignment colons:
229237
+--------+-------+
230238
```
231239

232-
`fancy_grid` draws a grid using box-drawing characters:
240+
`simple_grid` draws a grid using single-line box-drawing characters:
241+
242+
>>> print(tabulate(table, headers, tablefmt="simple_grid"))
243+
┌────────┬───────┐
244+
│ item │ qty │
245+
├────────┼───────┤
246+
│ spam │ 42 │
247+
├────────┼───────┤
248+
│ eggs │ 451 │
249+
├────────┼───────┤
250+
│ bacon │ 0 │
251+
└────────┴───────┘
252+
253+
`rounded_grid` draws a grid using single-line box-drawing characters with rounded corners:
254+
255+
>>> print(tabulate(table, headers, tablefmt="rounded_grid"))
256+
╭────────┬───────╮
257+
│ item │ qty │
258+
├────────┼───────┤
259+
│ spam │ 42 │
260+
├────────┼───────┤
261+
│ eggs │ 451 │
262+
├────────┼───────┤
263+
│ bacon │ 0 │
264+
╰────────┴───────╯
265+
266+
`double_grid` draws a grid using double-line box-drawing characters:
267+
268+
>>> print(tabulate(table, headers, tablefmt="double_grid"))
269+
╔════════╦═══════╗
270+
║ item ║ qty ║
271+
╠════════╬═══════╣
272+
║ spam ║ 42 ║
273+
╠════════╬═══════╣
274+
║ eggs ║ 451 ║
275+
╠════════╬═══════╣
276+
║ bacon ║ 0 ║
277+
╚════════╩═══════╝
278+
279+
`fancy_grid` draws a grid using a mix of single and
280+
double-line box-drawing characters:
233281

234282
```pycon
235283
>>> print(tabulate(table, headers, tablefmt="fancy_grid"))
@@ -244,6 +292,61 @@ corresponds to the `pipe` format without alignment colons:
244292
╘════════╧═══════╛
245293
```
246294

295+
`outline` is the same as the `grid` format but doesn't draw lines between rows:
296+
297+
>>> print(tabulate(table, headers, tablefmt="outline"))
298+
+--------+-------+
299+
| item | qty |
300+
+========+=======+
301+
| spam | 42 |
302+
| eggs | 451 |
303+
| bacon | 0 |
304+
+--------+-------+
305+
306+
`simple_outline` is the same as the `simple_grid` format but doesn't draw lines between rows:
307+
308+
>>> print(tabulate(table, headers, tablefmt="simple_outline"))
309+
┌────────┬───────┐
310+
│ item │ qty │
311+
├────────┼───────┤
312+
│ spam │ 42 │
313+
│ eggs │ 451 │
314+
│ bacon │ 0 │
315+
└────────┴───────┘
316+
317+
`rounded_outline` is the same as the `rounded_grid` format but doesn't draw lines between rows:
318+
319+
>>> print(tabulate(table, headers, tablefmt="rounded_outline"))
320+
╭────────┬───────╮
321+
│ item │ qty │
322+
├────────┼───────┤
323+
│ spam │ 42 │
324+
│ eggs │ 451 │
325+
│ bacon │ 0 │
326+
╰────────┴───────╯
327+
328+
`double_outline` is the same as the `double_grid` format but doesn't draw lines between rows:
329+
330+
>>> print(tabulate(table, headers, tablefmt="double_outline"))
331+
╔════════╦═══════╗
332+
║ item ║ qty ║
333+
╠════════╬═══════╣
334+
║ spam ║ 42 ║
335+
║ eggs ║ 451 ║
336+
║ bacon ║ 0 ║
337+
╚════════╩═══════╝
338+
339+
`fancy_outline` is the same as the `fancy_grid` format but doesn't draw lines between rows:
340+
341+
>>> print(tabulate(table, headers, tablefmt="fancy_outline"))
342+
╒════════╤═══════╕
343+
│ item │ qty │
344+
╞════════╪═══════╡
345+
│ spam │ 42 │
346+
│ eggs │ 451 │
347+
│ bacon │ 0 │
348+
╘════════╧═══════╛
349+
247350
`presto` is like tables formatted by Presto cli:
248351

249352
```pycon
@@ -532,6 +635,14 @@ column, in which case every column may have different number formatting:
532635
--- ----- -------
533636
```
534637

638+
`intfmt` works similarly for integers
639+
640+
>>> print(tabulate([["a",1000],["b",90000]], intfmt=","))
641+
- ------
642+
a 1,000
643+
b 90,000
644+
- ------
645+
535646
### Text formatting
536647

537648
By default, `tabulate` removes leading and trailing whitespace from text
@@ -745,7 +856,7 @@ To assign the same max width for all columns, a singular int scaler can be used.
745856
Use `None` for any columns where an explicit maximum does not need to be provided,
746857
and thus no automate multiline wrapping will take place.
747858

748-
The wraping uses the python standard [textwrap.wrap](https://docs.python.org/3/library/textwrap.html#textwrap.wrap)
859+
The wrapping uses the python standard [textwrap.wrap](https://docs.python.org/3/library/textwrap.html#textwrap.wrap)
749860
function with default parameters - aside from width.
750861

751862
This example demonstrates usage of automatic multiline wrapping, though typically
@@ -777,6 +888,7 @@ Usage of the command line utility
777888
-o FILE, --output FILE print table to FILE (default: stdout)
778889
-s REGEXP, --sep REGEXP use a custom column separator (default: whitespace)
779890
-F FPFMT, --float FPFMT floating point number format (default: g)
891+
-I INTFMT, --int INTFMT integer point number format (default: "")
780892
-f FMT, --format FMT set output table format; supported formats:
781893
plain, simple, github, grid, fancy_grid, pipe,
782894
orgtbl, rst, mediawiki, html, latex, latex_raw,
@@ -803,19 +915,19 @@ At the same time, `tabulate` is comparable to other table
803915
pretty-printers. Given a 10x10 table (a list of lists) of mixed text and
804916
numeric data, `tabulate` appears to be slower than `asciitable`, and
805917
faster than `PrettyTable` and `texttable` The following mini-benchmark
806-
was run in Python 3.8.3 in Windows 10 x64:
918+
was run in Python 3.8.2 in Ubuntu 20.04:
807919

808-
================================= ========== ===========
809-
Table formatter time, μs rel. time
810-
================================= ========== ===========
811-
csv to StringIO 12.5 1.0
812-
join with tabs and newlines 15.6 1.3
813-
asciitable (0.8.0) 191.4 15.4
814-
tabulate (0.8.9) 472.8 38.0
815-
tabulate (0.8.9, WIDE_CHARS_MODE) 789.6 63.4
816-
PrettyTable (0.7.2) 879.1 70.6
817-
texttable (1.6.2) 1352.2 108.6
818-
================================= ========== ===========
920+
================================== ========== ===========
921+
Table formatter time, μs rel. time
922+
================================== ========== ===========
923+
csv to StringIO 9.0 1.0
924+
join with tabs and newlines 10.7 1.2
925+
asciitable (0.8.0) 174.6 19.4
926+
tabulate (0.8.10) 385.0 42.8
927+
tabulate (0.8.10, WIDE_CHARS_MODE) 509.1 56.5
928+
PrettyTable (3.3.0) 827.7 91.9
929+
texttable (1.6.4) 952.1 105.7
930+
================================== ========== ===========
819931

820932

821933
Version history
@@ -839,10 +951,8 @@ To run tests on all supported Python versions, make sure all Python
839951
interpreters, `pytest` and `tox` are installed, then run `tox` in the root
840952
of the project source tree.
841953

842-
On Linux `tox` expects to find executables like `python2.6`,
843-
`python2.7`, `python3.4` etc. On Windows it looks for
844-
`C:\Python26\python.exe`, `C:\Python27\python.exe` and
845-
`C:\Python34\python.exe` respectively.
954+
On Linux `tox` expects to find executables like `python3.7`, `python3.8` etc.
955+
On Windows it looks for `C:\Python37\python.exe`, `C:\Python38\python.exe` etc. respectively.
846956

847957
To test only some Python environments, use `-e` option. For example, to
848958
test only against Python 3.7 and Python 3.10, run:
@@ -888,4 +998,5 @@ Wes Turner, Andrew Tija, Marco Gorelli, Sean McGinnis, danja100,
888998
endolith, Dominic Davis-Foster, pavlocat, Daniel Aslau, paulc,
889999
Felix Yan, Shane Loretz, Frank Busse, Harsh Singh, Derek Weitzel,
8901000
Vladimir Vrzić, 서승우 (chrd5273), Georgy Frolov, Christian Cwienk,
891-
Bart Broere, Vilhelm Prytz.
1001+
Bart Broere, Vilhelm Prytz, Alexander Gažo, Hugo van Kemenade,
1002+
jamescooke, Matt Warner.

appveyor.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
image: Visual Studio 2022
12
environment:
23

34
matrix:
@@ -7,16 +8,13 @@ environment:
78
# The list here is complete (excluding Python 2.6, which
89
# isn't covered by this document) at the time of writing.
910

10-
- PYTHON: "C:\\Python27"
11-
- PYTHON: "C:\\Python35"
12-
- PYTHON: "C:\\Python36"
1311
- PYTHON: "C:\\Python37"
1412
- PYTHON: "C:\\Python38"
15-
- PYTHON: "C:\\Python27-x64"
16-
- PYTHON: "C:\\Python35-x64"
17-
- PYTHON: "C:\\Python36-x64"
13+
- PYTHON: "C:\\Python39"
1814
- PYTHON: "C:\\Python37-x64"
1915
- PYTHON: "C:\\Python38-x64"
16+
- PYTHON: "C:\\Python39-x64"
17+
- PYTHON: "C:\\Python310-x64"
2018

2119
install:
2220
# We need wheel installed to build wheels

benchmark.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
from __future__ import print_function
41
from timeit import timeit
52
import tabulate
63
import asciitable
74
import prettytable
85
import texttable
96
import sys
10-
import codecs
11-
from platform import python_version_tuple
127

138
setup_code = r"""
149
from csv import writer
15-
try: # Python 2
16-
from StringIO import StringIO
17-
except: # Python 3
18-
from io import StringIO
10+
from io import StringIO
1911
import tabulate
2012
import asciitable
2113
import prettytable
2214
import texttable
2315
2416
25-
import platform
26-
if platform.platform().startswith("Windows") \
27-
and \
28-
platform.python_version_tuple() < ('3','6','0'):
29-
import win_unicode_console
30-
win_unicode_console.enable()
31-
32-
3317
table=[["some text"]+list(range(i,i+9)) for i in range(10)]
3418
3519
@@ -108,14 +92,7 @@ def benchmark(n):
10892
results, ["Table formatter", "time, μs", "rel. time"], "rst", floatfmt=".1f"
10993
)
11094

111-
from platform import platform
112-
113-
if platform().startswith("Windows"):
114-
print(table)
115-
elif python_version_tuple()[0] < "3":
116-
print(codecs.encode(table, "utf-8"))
117-
else:
118-
print(table)
95+
print(table)
11996

12097

12198
if __name__ == "__main__":

0 commit comments

Comments
 (0)