Skip to content

Commit 53f7a61

Browse files
authored
pass colalign argument through to tabulate (#97)
In tabulate_adapter.adapter(), permit the colalign argument to be passed in kwargs. This argument can be used by the application to set known desirable column alignments based on column types, without expensive numparse checks. In addition, this works reliably with nullable numeric columns, whereas the numparse logic does not.
1 parent c34ae9f commit 53f7a61

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Version 2.8.0
4+
5+
(released on 2026-01-24)
6+
7+
- Pass `colalign` argument through to `tabulate`.
8+
39
## Version 2.7.0
410

511
(released on 2025-07-28)

cli_helpers/tabular_output/tabulate_adapter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ def addColorInElt(elt):
225225

226226
def adapter(data, headers, table_format=None, preserve_whitespace=False, **kwargs):
227227
"""Wrap tabulate inside a function for TabularOutputFormatter."""
228-
keys = ("floatfmt", "numalign", "stralign", "showindex", "disable_numparse")
228+
keys = (
229+
"floatfmt",
230+
"numalign",
231+
"stralign",
232+
"showindex",
233+
"disable_numparse",
234+
"colalign",
235+
)
229236
tkwargs = {"tablefmt": table_format}
230237
tkwargs.update(filter_dict_by_key(kwargs, keys))
231238

tests/tabular_output/test_tabulate_adapter.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ def test_tabulate_wrapper():
4242
└─────────┴────────┘"""
4343
)
4444

45+
data = [["abc", 1], ["d", 456]]
46+
headers = ["letters", "number"]
47+
output = tabulate_adapter.adapter(
48+
iter(data),
49+
headers,
50+
colalign=["left", "left"],
51+
table_format="psql_unicode",
52+
)
53+
assert "\n".join(output) == dedent(
54+
"""\
55+
┌─────────┬────────┐
56+
│ letters │ number │
57+
├─────────┼────────┤
58+
│ abc │ 1 │
59+
│ d │ 456 │
60+
└─────────┴────────┘"""
61+
)
62+
4563
data = [["{1,2,3}", "{{1,2},{3,4}}", "{å,魚,текст}"], ["{}", "<null>", "{<null>}"]]
4664
headers = ["bigint_array", "nested_numeric_array", "配列"]
4765
output = tabulate_adapter.adapter(iter(data), headers, table_format="psql")

0 commit comments

Comments
 (0)