diff --git a/tabulate.py b/tabulate.py index 8fc2bfe..1140bb0 100644 --- a/tabulate.py +++ b/tabulate.py @@ -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 @@ -1211,8 +1214,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, @@ -1523,8 +1526,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 diff --git a/test/test_api.py b/test/test_api.py index 9b5d74f..bf56e82 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -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)