-
Notifications
You must be signed in to change notification settings - Fork 179
Open
Description
Description
Problem
The current table formats (especially github and pipe) add significant whitespace padding to align all columns, which creates unnecessarily large output for tables with many columns or varying cell widths. This becomes problematic when:
- Working with large tables (e.g., 100+ columns or 1000+ rows)
- Processing tables for downstream tasks like tokenization or LLM input
- Storing or transmitting table data where size matters
Example
Current behavior with tablefmt="github":
from tabulate import tabulate
data = [
["Syntax", "Description", "Test Text"],
["Header", "Title", "Here's this"],
["Paragraph", "Text", "And more"]
]
print(tabulate(data[1:], headers=data[0], tablefmt="github"))Output (215 characters):
| Syntax | Description | Test Text |
|-------------|---------------|---------------|
| Header | Title | Here's this |
| Paragraph | Text | And more |
Proposed Solution
Add a compact parameter (or a new compact_github/compact_pipe format) that produces minimal whitespace while maintaining valid markdown:
print(tabulate(data[1:], headers=data[0], tablefmt="github", compact=True))
# or
print(tabulate(data[1:], headers=data[0], tablefmt="compact_github"))Desired output (145 characters, 32% smaller):
| Syntax | Description | Test Text |
| - | - | - |
| Header | Title | Here's this |
| Paragraph | Text | And more |
Key Requirements
- Remove column padding: No extra spaces to align columns
- Minimal separators: Use single dash (
-) instead of multiple dashes (-------) - Preserve alignment marks: Keep
:---,:---:, and---:for left/center/right alignment - Maintain validity: Output should still be valid markdown
Example with Alignment
Input with alignment:
data = [
["Left", "Center", "Right"],
["A", "B", "C"]
]
# Assuming alignment can be specified somehowCompact output should preserve alignment marks:
| Left | Center | Right |
| :- | :-: | -: |
| A | B | C |
Benefits
- Space savings: 30-60% reduction in character count for typical tables
- Performance: Faster processing for large tables
- Compatibility: Still produces valid markdown tables
- Use cases: Better for LLM tokenization, data transmission, storage
Additional Context
Environment:
- Python version: 3.12+
- tabulate version: 0.9.0
I'm happy to contribute a PR if there's interest.
Metadata
Metadata
Assignees
Labels
No labels