termtables icon indicating copy to clipboard operation
termtables copied to clipboard

index out of range error

Open issadarkthing opened this issue 5 years ago • 5 comments

image

issadarkthing avatar May 03 '20 04:05 issadarkthing

Always copy-and-paste your code, never screenshot it. Copy-and-pasting makes it searchable.

nschloe avatar May 06 '20 07:05 nschloe

Also, I need a minimal example that reproduces the error.

nschloe avatar May 06 '20 07:05 nschloe

I was able to replicate the error when a row contains: \n

Try with: "something blabla \n more etc"

maborak avatar May 10 '20 03:05 maborak

sorry for using screenshot. the error occurs exactly like what @maborak asserts

issadarkthing avatar May 14 '20 05:05 issadarkthing

Yes, screenshots are terrible. Not to pile on, but if you are going to bother reporting a problem, make it something actionable.

I think the problem is in this method:

def _hjoin_multiline(join_char, strings):
    """Horizontal join of multiline strings"""
    cstrings = [string.split("\n") for string in strings]
    max_num_lines = max(len(item) for item in cstrings)
    pp = []
    for k in range(max_num_lines):
        p = [cstring[k] for cstring in cstrings]
        pp.append(join_char + join_char.join(p) + join_char)

    return "\n".join([p.rstrip() for p in pp])

max_num_lines is the maximum number of lines in at least one cell for all cells in a row. However, if a cell has fewer than that, then k index will be out of range of cstring

Reproduce with:

        header = ["A", "B\nB","C"]
        data = [["a", "b", "c"]]
        tt.print(
            data,
            header=header,
        )

BradHolmes avatar Feb 16 '22 12:02 BradHolmes