Ask Your Question
2

Issue Printing Tables in Jupyter Notebook

asked 2019-04-03 18:35:30 +0100

TristanWL gravatar image

I've been trying to display some tables in sage, in particular I would like to display tables that contain matrices as nice output in a jupyter notebook.

I seem to not be able to get table to work at all. In particular, if I open a new notebook and run the chunk

%display latex
blah = [('A', 'B', 'C'), (0, 1, 2), (3, 4, 5), (6, 7, 8)]
table(blah)

It returns

PGRpdiBjbGFzcz0ibm90cnVuY2F0ZSI+Cjx0YWJsZSAgY2xhc3M9InRhYmxlX2Zvcm0iPgo8dGJvZHk+Cjx0ciBjbGFzcyA9InJvdy1hIj4KPHRkPkE8L3RkPgo8dGQ+QjwvdGQ+Cjx0ZD5DPC90ZD4KPC90cj4KPHRyIGNsYXNzID0icm93LWIiPgo8dGQ+PHNjcmlwdCB0eXBlPSJtYXRoL3RleCI+MDwvc2NyaXB0PjwvdGQ+Cjx0ZD48c2NyaXB0IHR5cGU9Im1hdGgvdGV4Ij4xPC9zY3JpcHQ+PC90ZD4KPHRkPjxzY3JpcHQgdHlwZT0ibWF0aC90ZXgiPjI8L3NjcmlwdD48L3RkPgo8L3RyPgo8dHIgY2xhc3MgPSJyb3ctYSI+Cjx0ZD48c2NyaXB0IHR5cGU9Im1hdGgvdGV4Ij4zPC9zY3JpcHQ+PC90ZD4KPHRkPjxzY3JpcHQgdHlwZT0ibWF0aC90ZXgiPjQ8L3NjcmlwdD48L3RkPgo8dGQ+PHNjcmlwdCB0eXBlPSJtYXRoL3RleCI+NTwvc2NyaXB0PjwvdGQ+CjwvdHI+Cjx0ciBjbGFzcyA9InJvdy1iIj4KPHRkPjxzY3JpcHQgdHlwZT0ibWF0aC90ZXgiPjY8L3NjcmlwdD48L3RkPgo8dGQ+PHNjcmlwdCB0eXBlPSJtYXRoL3RleCI+Nzwvc2NyaXB0PjwvdGQ+Cjx0ZD48c2NyaXB0IHR5cGU9Im1hdGgvdGV4Ij44PC9zY3JpcHQ+PC90ZD4KPC90cj4KPC90Ym9keT4KPC90YWJsZT4KPC9kaXY+

which appears to be some sort of hash value? I can't find anything on this to help debug.

For reference, I'm still running sage 8.4. The environments on the system I'm working on are a little messed up, so I could update to the newest version if there is reason to believe that's the issue, but I would rather not if I can avoid it.

edit retag flag offensive close merge delete

Comments

Are you running a Python 3 version of Sage? That is the only way I have been able to reproduce this problem. Note that the Python 3 version is still somewhat experimental.

John Palmieri gravatar imageJohn Palmieri ( 2019-04-14 00:47:24 +0100 )edit

Sorry for the late reply, I had to finish my undergraduate thesis.

This was indeed on the python3 version of sage and switching to python2 fixed it. I did not realize the machine I was running on had built sage with python3 and I apologize for not mentioning that detail. It didn't occur to me to check until you pointed it out.

TristanWL gravatar imageTristanWL ( 2019-04-27 22:46:46 +0100 )edit

Fixed in SageMath 8.8.beta5. In particular, works fine in SageMath 8.8.

slelievre gravatar imageslelievre ( 2019-06-30 14:45:17 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-04-06 12:58:35 +0100

slelievre gravatar image

updated 2019-06-01 17:01:45 +0100

Thanks for reporting! I confirm the same behaviour with SageMath 8.7. Fixing this is now tracked at

As a workaround, some alternative solutions are offered as answers to

To make the import statements work, install the corresponding extra packages:

sage --pip install pandas
sage --pip install tabletext
sage --pip install tabulate

Edit (2019-06-01). Sage Trac ticket 27656 (Fix table display in Jupyter) was merged in SageMath 8.8.beta5. As a result, printing tables in Jupyter should work fine in SageMath 8.8.beta5 and above.

edit flag offensive delete link more

Comments

Ah, thanks for the reference. Does this mean that the issue is entirely on the ipython side of things? These seem to be alternative methods for printing tables, but don't explain why I'm getting some hash value when I try to use the builtin table command.

That being said, I'm not really attached to the table command other than the convenience, so I'll dive into this thread and see if I can get something else to work.

TristanWL gravatar imageTristanWL ( 2019-04-07 19:12:19 +0100 )edit

That said, table has a long and distinguished history in Sage, so that should definitely be fixed in Jupyter.

kcrisman gravatar imagekcrisman ( 2019-04-09 19:42:45 +0100 )edit

@kcrisman - There is now a Sage Trac ticket for this problem, I edited my answer to make it clearer this is indeed a bug, and the "solutions" I first gave can be thought of as a workaround until this is fixed.

slelievre gravatar imageslelievre ( 2019-04-13 13:27:43 +0100 )edit

The "some hash value" is simply the base-64 encoding of the table. I know images are passed to the notebook in base64 encoding, and for some reason it's (incorrectly?) doing that with the table as well. You can see that by running import base64; print(base64.b64decode("""PGRpdiBjbG..."""))

Iguananaut gravatar imageIguananaut ( 2019-04-15 15:24:51 +0100 )edit

@slelievre thanks! In fact I think it has been closed :)

kcrisman gravatar imagekcrisman ( 2019-05-08 22:14:07 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2019-04-03 18:35:30 +0100

Seen: 1,502 times

Last updated: Jun 01 '19