Skip to content

Commit

Permalink
fix FutureWarning about SEPARATING_LINE
Browse files Browse the repository at this point in the history
  • Loading branch information
astanin committed Jun 22, 2022
1 parent 38d345b commit 3f0757e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ All versions can then be easily installed with something like:

Don't forget to change your `PATH` so that `tox` knows how to find all the installed versions. Something like

export PATH="${PATH}:${HOME}/.pyenv/shims"
export PATH="${PATH}:${HOME}/.pyenv/shims"

To test only some Python environments, use `-e` option. For example, to
test only against Python 3.7 and Python 3.10, run:
Expand Down
18 changes: 12 additions & 6 deletions tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ def _is_file(f):
)


def _is_separating_line(row):
row_type = type(row)
is_sl = (row_type == list or row_type == str) and (
(len(row) >= 1 and row[0] == SEPARATING_LINE)
or (len(row) >= 2 and row[1] == SEPARATING_LINE)
)
return is_sl


def _pipe_segment_with_colons(align, colwidth):
"""Return a segment of a horizontal line with optional colons which
indicate column's alignment (as in `pipe` output format)."""
Expand Down Expand Up @@ -1100,8 +1109,7 @@ def _remove_separating_lines(rows):
separating_lines = []
sans_rows = []
for index, row in enumerate(rows):
row_type = type(row)
if (row_type == list or row_type == str) and row[0] == SEPARATING_LINE:
if _is_separating_line(row):
separating_lines.append(index)
else:
sans_rows.append(row)
Expand Down Expand Up @@ -1307,7 +1315,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):

headers = list(map(str, headers))
# rows = list(map(list, rows))
rows = list(map(lambda r: r if r == SEPARATING_LINE else list(r), rows))
rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))

# add or remove an index column
showindex_is_a_str = type(showindex) in [str, bytes]
Expand Down Expand Up @@ -2139,9 +2147,7 @@ def _format_table(fmt, headers, rows, colwidths, colaligns, is_multiline, rowali
for row in padded_rows:
# test to see if either the 1st column or the 2nd column (account for showindex) has
# the SEPARATING_LINE flag
if row[0].strip() == SEPARATING_LINE or (
len(row) > 1 and row[1].strip() == SEPARATING_LINE
):
if _is_separating_line(row):
_append_line(lines, padded_widths, colaligns, separating_line)
else:
append_row(lines, row, padded_widths, colaligns, fmt.datarow)
Expand Down
3 changes: 2 additions & 1 deletion test/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def test_plain_maxcolwidth_autowraps():
)
assert_equal(expected, result)


def test_plain_maxcolwidth_autowraps_with_sep():
"Output: maxcolwidth will result in autowrapping longer cells and separating line"
table = [
Expand Down Expand Up @@ -1142,7 +1143,7 @@ def test_fancy_grid_multiline_row_align():
result = tabulate(table, tablefmt="fancy_grid", rowalign=[None, "center", "bottom"])
assert_equal(expected, result)


def test_outline():
"Output: outline with headers"
expected = "\n".join(
Expand Down

0 comments on commit 3f0757e

Please sign in to comment.