gregbanks / python-tabulate

fork of https://bitbucket.org/astanin/python-tabulate
MIT License
177 stars 14 forks source link

Issues with width of separator when using non-gridded table layout #11

Open AnjoMan opened 1 year ago

AnjoMan commented 1 year ago

When i use SEPARATING_LINE in 'mixed_grid' or 'simple_outline', i get an extra row (according to the docs, this is how the separator is done for some styles. However, i noticed the extra row does not seem to adopt the width of the table, but just has a little empty string.

An MWE:

from tabulate import tabulate, SEPARATING_LINE
mse_table = tabulate(
    [
        ["Mean-Squared Current Error", "∑ΔI² / N",  "0.00000000000000000032486767"  + " A²"],
        ["Mean-Squared Voltage Error", "∑ΔV² / N",  "0.00000000000000000000000019092038" + " V p.u.²"],
        SEPARATING_LINE,
        ["Mean-Absolute Current Error", "∑|ΔI| / N", "0.00000000021306265" + " A"],
        ["Mean-Absolute Voltage Error", "∑|ΔV| / N", "0.000000000000341719" + " V p.u."]
    ],
    headers=["Summarizing Error", "Formula", "Value"],
    tablefmt="mixed_grid"
)

print(mse_table)

This produces the following table:


┌─────────────────────────────┬───────────┬────────────────────────────────────────────┐
│ Summarizing Error           │ Formula   │ Value                                      │
├─────────────────────────────┼───────────┼────────────────────────────────────────────┤
│ Mean-Squared Current Error  │ ∑ΔI² / N  │ 0.00000000000000000032486767 A²            │
│ Mean-Squared Voltage Error  │ ∑ΔV² / N  │ 0.00000000000000000000000019092038 V p.u.² │
│  │
│ Mean-Absolute Current Error │ ∑|ΔI| / N │ 0.00000000021306265 A                      │
│ Mean-Absolute Voltage Error │ ∑|ΔV| / N │ 0.000000000000341719 V p.u.                │
└─────────────────────────────┴───────────┴────────────────────────────────────────────┘

It seems to me like there should ideally be a step that computes the width of the row, or injects it a bit more formally in the table so its width is properly derived from whatever tabulate picks for trhe rest of the table.

AnjoMan commented 1 year ago

A workaround appears to be using [""], not SEPARATING_LINE.