Skip to content

Commit 2d3c3df

Browse files
authored
Merge branch 'master' into patch-1
2 parents 392be0f + 8a26993 commit 2d3c3df

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tabulate/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,17 @@ def _is_file(f):
102102
)
103103

104104

105+
def _is_separating_line_value(value):
106+
return type(value) == str and value.strip() is SEPARATING_LINE
107+
108+
105109
def _is_separating_line(row):
106110
row_type = type(row)
107111
is_sl = (row_type == list or row_type == str) and (
108-
(len(row) >= 1 and row[0] is SEPARATING_LINE)
109-
or (len(row) >= 2 and row[1] is SEPARATING_LINE)
112+
(len(row) >= 1 and _is_separating_line_value(row[0]))
113+
or (len(row) >= 2 and _is_separating_line_value(row[1]))
110114
)
115+
111116
return is_sl
112117

113118

test/test_output.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,6 +2935,27 @@ def test_list_of_lists_with_index_with_sep_line():
29352935
assert_equal(expected, result)
29362936

29372937

2938+
def test_with_padded_columns_with_sep_line():
2939+
table = [
2940+
["1", "one"], # "1" as a str on purpose
2941+
[1_000, "one K"],
2942+
SEPARATING_LINE,
2943+
[1_000_000, "one M"],
2944+
]
2945+
expected = "\n".join(
2946+
[
2947+
"+---------+-------+",
2948+
"| 1 | one |",
2949+
"| 1000 | one K |",
2950+
"|---------+-------|",
2951+
"| 1000000 | one M |",
2952+
"+---------+-------+",
2953+
]
2954+
)
2955+
result = tabulate(table, tablefmt="psql")
2956+
assert_equal(expected, result)
2957+
2958+
29382959
def test_list_of_lists_with_supplied_index():
29392960
"Output: a table with a supplied index"
29402961
dd = zip(*[list(range(3)), list(range(101, 104))])

0 commit comments

Comments
 (0)