astanin / python-tabulate

Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate.
https://pypi.org/project/tabulate/
MIT License
2.11k stars 163 forks source link

{heavy,simple}_outline formats do not handle mulitline values correctly #203

Closed astanin closed 1 year ago

astanin commented 1 year ago

Wrong:

>>> print(tabulate([["a\nbb", "a\nbb\nccc\ndddd"]], rowalign="center", tablefmt="heavy_outline"))
┏━┳━┓
┃ a
bb  ┃ a
bb
ccc
dddd  ┃
┗━┻━┛

Correct:

>>> print(tabulate([["a\nbb", "a\nbb\nccc\ndddd"]], rowalign="center", tablefmt="grid"))
+----+------+
|    | a    |
| a  | bb   |
| bb | ccc  |
|    | dddd |
+----+------+

heavy_grid works fine too:

>>> print(tabulate([["a\nbb", "a\nbb\nccc\ndddd"]], rowalign="center", tablefmt="heavy_grid"))
┏━━━━┳━━━━━━┓
┃    ┃ a    ┃
┃ a  ┃ bb   ┃
┃ bb ┃ ccc  ┃
┃    ┃ dddd ┃
┗━━━━┻━━━━━━┛

@kdeldycke You have implemented these formats. Would you mind to take a look?

kdeldycke commented 1 year ago

Hmmm. It always occurred to me that all styles from the *_outline family never supported multi-lines cells. I merely added new styles following the pattern introduced by @vrza in #80. So if the latter was supposed to work, something else broke the rendering. I'll try to get more evidences...

kdeldycke commented 1 year ago

Yep, all *_outline styles are broken since the beginning, way before I added the new variants:

>>> import tabulate
>>> tabulate.__version__
'0.8.8'

>>> from tabulate import tabulate
>>> print(tabulate([["a\nbb", "a\nbb\nccc\ndddd"]], rowalign="center", tablefmt="fancy_outline"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: tabulate() got an unexpected keyword argument 'rowalign'

>>> print(tabulate([["a\nbb", "a\nbb\nccc\ndddd"]], tablefmt="fancy_outline"))
╒═╤═╕
│ a
bb  │ a
bb
ccc
dddd  │
╘═╧═╛
kdeldycke commented 1 year ago

Just found a solution:

>>> import tabulate
>>> tabulate.__version__
'0.9.0'

>>> print(tabulate.tabulate([["a\nbb", "a\nbb\nccc\ndddd"]], rowalign="center", tablefmt="heavy_outline"))
┏━┳━┓
┃ a
bb  ┃ a
bb
ccc
dddd  ┃
┗━┻━┛

>>> tabulate.multiline_formats.update({'heavy_outline':'heavy_outline'})
>>> print(tabulate.tabulate([["a\nbb", "a\nbb\nccc\ndddd"]], rowalign="center", tablefmt="heavy_outline"))
┏━━━━┳━━━━━━┓
┃ a  ┃ a    ┃
┃ bb ┃ bb   ┃
┃    ┃ ccc  ┃
┃    ┃ dddd ┃
┗━━━━┻━━━━━━┛

Give me a couple of minutes and I'll produce a PR.

kdeldycke commented 1 year ago

I just proposed a fix in: https://github.com/astanin/python-tabulate/pull/204

astanin commented 1 year ago

Perfect, thanks!