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

qtconsole + _repr_html_ bug #2275

Closed
csakhil opened this issue Nov 16, 2012 · 12 comments

Comments

@csakhil
Copy link

commented Nov 16, 2012

Printing a pandas.DataFrame in IPython's qtconsole tries to use _repr_html_. This method returns None if the terminal window that started the IPython session is too small.

I'm not sure this behaviour is right. When you're in the qtconsole, _repr_html_ should check the size of the qtconsole window and not the the size of the terminal that started the session.

Here are some steps to reproduce the issue:

  1. Create a very small terminal window and run ipython qtconsole.
  2. Create a pandas.DataFrame called df.
  3. Run df.head() in IPython. You should notice that the HTML representation of the table is not used.
  4. Maximize the small terminal window from step 1.
  5. Run df.head() in IPython. The HTML representation is now used.

I would guess the easiest way to fix this would be to add a qtconsole "os" in get_terminal_size in util/terminal.py and use Qt hooks to figure out the dimensions of the qtconsole.

@lodagro

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2012

Besides the qtconsole this is also the case in the ipython notebook (i thought there was an issue about this one too, but can`t find it). Idle #1714, has a similar problem.

Sounds like you have a solution for the qtconsole, can you elaborate? I added the get_terminal_size code, but i`m unfamiliar with Qt.

@ghost

This comment has been minimized.

Copy link

commented Nov 19, 2012

IPython zmq front ends run in a seperate process from the kernel, and I couldn't locate any interface for
querying the front end for things like geometry.

Though, It's possible to detect whether the code is running under IPython and under what specific front-end.

@csakhil

This comment has been minimized.

Copy link
Author

commented Nov 19, 2012

The easiest solution might be to always use the HTML representation if within a qtconsole or IPython notebook.

@lodagro

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2012

Reason not always _repr_html_ is used, is to handle large frames (see also discussion in #772).
Maybe we could bypass auto detect of terminal size in qtconsole, and use hard coded values for max columns/rows (html has scrollable divs)? And if the frame is too big (it would take too long to render) switch over to summary view.

For reference also mentioning #829 (no means to get ipython notbook size).

@changhiskhan

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2012

What's the best way to test whether the code is running under terminal or some graphical frontend? just check whether get_ipython returns ZMQInteractiveShell?

@ghost

This comment has been minimized.

Copy link

commented Nov 29, 2012

yes, And:

get_ipython().config['KernelApp']['parent_appname']

gets you the specific front-end since at least 0.12 I believe.

@changhiskhan

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2012

hmmm...how do you test this?

@ghost

This comment has been minimized.

Copy link

commented Nov 29, 2012

inject into globals()/context manager?

@changhiskhan

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2012

yeah, can't think of anything better.
I'll just have to make a fake get_ipython function etc.
Thanks!

@ghost

This comment has been minimized.

Copy link

commented Nov 29, 2012

you could also wrap get_ipython inside something in common, and invoke that
rather then get_ipython directly, then add some testing hooks to set the return value.
cleaner, but perhaps overkill.

@changhiskhan

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2012

probably fine for now.

@wesm

This comment has been minimized.

Copy link
Member

commented Nov 30, 2012

In addition to Chang's PR, I disabled HTML output altogether until there's a way to get the window size in characters

@wesm wesm closed this Nov 30, 2012

@ghost ghost referenced this issue Apr 19, 2013
takluyver pushed a commit to takluyver/pandas that referenced this issue Nov 19, 2013
y-p
ENH: let display.notebook_repr_html control HTML repr in qtconsole ag…
…ain.

Where it belongs.

pandas-dev#2275 (comment)

It'll probably never happen that QTconsole will report it's width, let alone
in characters (variable-width font and all). Best let the user decide.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.