Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table class does not like uneven columns #61

Open
pfuntner opened this issue Jan 3, 2020 · 0 comments
Open

Table class does not like uneven columns #61

pfuntner opened this issue Jan 3, 2020 · 0 comments

Comments

@pfuntner
Copy link
Owner

pfuntner commented Jan 3, 2020

I found a bug when the Table class of table.py when you try to add a row with less columns than the number of headings:

$ cat ~/python/tabletest
#! /usr/bin/env python3

import logging
import argparse

from table import Table

parser = argparse.ArgumentParser(description='investigate table bug')
parser.add_argument('--boom', action='store_true', help='Cause exception')
parser.add_argument('-v', '--verbose', action='count', help='Enable debugging')
args = parser.parse_args()

logging.basicConfig(format='%(asctime)s %(levelname)s %(pathname)s:%(lineno)d %(msg)s')
log = logging.getLogger()
# log.setLevel(logging.DEBUG if args.verbose else logging.WARNING)
log.setLevel(logging.WARNING - (args.verbose or 0)*10)

table = Table('col1', 'col2')
table.add('row1, col1', 'row1, col2')
if args.boom:
  table.add('row2, col1')
print(str(table))
$ ~/python/tabletest
col1        col2
row1, col1  row1, col2

$ ~/python/tabletest  --boom
Traceback (most recent call last):
  File "/home/jpfuntne/python/tabletest", line 21, in <module>
    table.add('row2, col1')
  File "/home/jpfuntne/repos/fun/table.py", line 719, in add
    self.root.append({name: str(row[pos]) for (pos, name) in enumerate(self.headings)})
  File "/home/jpfuntne/repos/fun/table.py", line 719, in <dictcomp>
    self.root.append({name: str(row[pos]) for (pos, name) in enumerate(self.headings)})
IndexError: tuple index out of range
$

I don't know if this happens when you try to add a row that has more columns.

I'm not saying the class needs to pad or truncate columns when a row doesn't match the headings but the class should handle the situation better and make it clear that the number of columns is not correct.

pfuntner pushed a commit to pfuntner/fun that referenced this issue Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant