Skip to content

BUG: problems with qtconsole and _repr_html #2392

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,17 @@ def in_interactive_session():
import __main__ as main
return not hasattr(main, '__file__')

def in_qtconsole():
"""
check if we're inside an IPython qtconsole
"""
try:
ip = get_ipython()
if ip.config['KernelApp']['parent_appname'] == 'ipython-qtconsole':
return True
except:
return False

# Unicode consolidation
# ---------------------
#
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,10 @@ def _need_info_repr_(self):
particular DataFrame.
"""

terminal_width, terminal_height = get_terminal_size()
if com.in_qtconsole():
terminal_width, terminal_height = 10, 100
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these backwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the problem with qtconsole is that the terminal size isn't reflective of the window size so I'm skipping that check here and set it to some default.
I don't know of an easy way for the ipython shell to query the window for geometry.

else:
terminal_width, terminal_height = get_terminal_size()
max_rows = (terminal_height if get_option("print_config.max_rows") == 0
else get_option("print_config.max_rows"))
max_columns = get_option("print_config.max_columns")
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,21 @@ def test_repr_html(self):

fmt.reset_printoptions()

def test_fake_qtconsole_repr_html(self):
def get_ipython():
return {'config' :
{'KernelApp' :
{'parent_appname' : 'ipython-qtconsole'}}}

repstr = self.frame._repr_html_()
self.assert_(repstr is not None)

fmt.set_printoptions(max_rows=5, max_columns=2)

self.assert_(self.frame._repr_html_() is None)

fmt.reset_printoptions()

def test_to_html_with_classes(self):
df = pandas.DataFrame()
result = df.to_html(classes="sortable draggable")
Expand Down