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

IndexError when Table(..., header=None) #15

Closed
ickc opened this issue Nov 13, 2016 · 8 comments
Closed

IndexError when Table(..., header=None) #15

ickc opened this issue Nov 13, 2016 · 8 comments
Assignees

Comments

@ickc
Copy link
Collaborator

ickc commented Nov 13, 2016

Hi,

From Table(*args, *, header=None, caption=None, alignment=None, width=None), the default value of header is None. However, using a modified version of the docstring:

x = [Para(Str('Something')), Para(Space, Str('else'))]
c1 = TableCell(*x)
c2 = TableCell(Header(Str('Title')))
rows = [TableRow(c1, c2)]
table = Table(*rows)

will result in

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-11-f81c7d6eb71b> in <module>()
      3 c2 = TableCell(Header(Str('Title')))
      4 rows = [TableRow(c1, c2)]
----> 5 table = Table(*rows)

/usr/local/lib/python3.5/site-packages/panflute/elements.py in __init__(self, header, caption, alignment, width, *args)
   1051         self.rows = len(self.content)
   1052         self.cols = len(self.content[0].content)
-> 1053         self.header = header if header else []
   1054         self.caption = caption if caption else []
   1055 

/usr/local/lib/python3.5/site-packages/panflute/elements.py in header(self, value)
   1082             msg = 'table header has an incorrect number of cols:'
   1083             msg += ' {} rows but expected {}'.format(len(value), self.cols)
-> 1084             raise IndexError(msg)
   1085 
   1086     @property

IndexError: table header has an incorrect number of cols: 0 rows but expected 2

It would be the same if the last line becomes table = Table(*rows, header=None).

So it always expected a list as long as the no. of columns.

Thanks.

@sergiocorreia sergiocorreia self-assigned this Nov 13, 2016
@sergiocorreia
Copy link
Owner

I just pushed a fix that should work, but since I had to touch several parts of the code I wouldn't be surprised if I missed something.

BTW, TravisCI is failing right now because I can't get pandoc to install on their docker containers, but the tests are passing on my side

@ickc
Copy link
Collaborator Author

ickc commented Nov 13, 2016

I recently have experimented quite a few different ways of setting up travis for pandoc project. Do you want me to pull request on the travis setup? (and you want sudo = false, right?)

@sergiocorreia
Copy link
Owner

Yes, I think sudo=false is by default in TravisCI. My current build is quite simple, but feel free to send me any PR if you see anything that can be improved (this is the first time I've used Travis).

I also suspect there's a bug that pops up only in some systems and that might be picked up by Travis in this case. I need to change the JSON loading code to fix that for good, but that would probably wait a few days unless you or someone else spot that bug on the field (so it's not only Travis's specific config that gives the bug)

@ickc
Copy link
Collaborator Author

ickc commented Nov 14, 2016

I just pushed a fix that should work, but since I had to touch several parts of the code I wouldn't be surprised if I missed something.

I tried updating panflute, but the version is still 1.4.2. By the way, can you provide a quicker way to check version like the attribute panflute.__version__?

Thanks.

@ickc
Copy link
Collaborator Author

ickc commented Nov 14, 2016

I can confirm 1.4.3 works. I installed using pip install git+git://github.com/sergiocorreia/panflute.git. It's still 1.4.2 in panflute 1.4.2 : Python Package Index.

@sergiocorreia
Copy link
Owner

Having a .version variable makes sense; I'll probably follow suggestion 3 of this link

sergiocorreia added a commit that referenced this issue Nov 15, 2016
EG:

>>> import panflute
>>> panflute.__version__
'1.4.5'
@ickc
Copy link
Collaborator Author

ickc commented Nov 29, 2016

I think this one need to reopen:

from panflute import *
x = [Para(Str('Something')), Para(Space, Str('else'))]
c1 = TableCell(*x)
c2 = TableCell(Header(Str('Title')))
rows = [TableRow(c1, c2)]
table = Table(*rows, header=None)
print(convert_text([table], input_format='panflute', output_format='native'))

will output

[Table [] [AlignDefault,AlignDefault] [0.0,0.0]
 []
 [[[Para [Str "Something"]
   ,Para [Space,Str "else"]]
  ,[Header 1 ("",[],[]) [Str "Title"]]]]]

Notice the 2nd line is an empty "list". pandoc seems to parse this just fine. But the problem is when this is passed to panflute, panflute will complain IndexError: table header has an incorrect number of cols: 0 rows but expected 2.

And in the case when pandoc has no header row, it will output a "list" of "list" that looks like this:

 [[]
 ,[]]

So even if pandoc is fine with [], a list of empty lists might be better because it is what pandoc output, and because this is what "panflute requires".

sergiocorreia added a commit that referenced this issue Nov 29, 2016
@sergiocorreia
Copy link
Owner

Just submitted a fix:

  • The bug was in converting the table to json. Now it prints the list of empty lists.
  • I also allow convert_text(elem) where elem is any arbitrary panflute element (so you don't have to wrap it in a list.
  • Also added a test case for this

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

2 participants