Skip to content

Commit

Permalink
allow to specify align in pretty formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
gfrlv committed May 29, 2020
1 parent 2552e6d commit 56725b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def _is_file(f):

_DEFAULT_FLOATFMT = "g"
_DEFAULT_MISSINGVAL = ""
# default align will be overwritten by "left", "center" or "decimal"
# depending on the formatter
_DEFAULT_ALIGN = "default"


# if True, enable wide-character (CJK) support
Expand Down Expand Up @@ -1146,8 +1149,8 @@ def tabulate(
headers=(),
tablefmt="simple",
floatfmt=_DEFAULT_FLOATFMT,
numalign="decimal",
stralign="left",
numalign=_DEFAULT_ALIGN,
stralign=_DEFAULT_ALIGN,
missingval=_DEFAULT_MISSINGVAL,
showindex="default",
disable_numparse=False,
Expand Down Expand Up @@ -1458,8 +1461,11 @@ def tabulate(
if tablefmt == "pretty":
min_padding = 0
disable_numparse = True
numalign = "center"
stralign = "center"
numalign = "center" if numalign == _DEFAULT_ALIGN else numalign
stralign = "center" if stralign == _DEFAULT_ALIGN else stralign
else:
numalign = "decimal" if numalign == _DEFAULT_ALIGN else numalign
stralign = "left" if stralign == _DEFAULT_ALIGN else stralign

# optimization: look for ANSI control codes once,
# enable smart width functions only if a control code is found
Expand Down
4 changes: 2 additions & 2 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def test_tabulate_signature():
("headers", ()),
("tablefmt", "simple"),
("floatfmt", "g"),
("numalign", "decimal"),
("stralign", "left"),
("numalign", "default"),
("stralign", "default"),
("missingval", ""),
]
_check_signature(tabulate, expected_sig)
Expand Down

0 comments on commit 56725b5

Please sign in to comment.