From 8337eb4d7dc4231831421e8588e2478d513f6e52 Mon Sep 17 00:00:00 2001 From: Chang She Date: Thu, 29 Nov 2012 12:25:11 -0500 Subject: [PATCH 1/2] BUG: problems with qtconsole and _repr_html #2275 --- pandas/core/common.py | 11 +++++++++++ pandas/core/frame.py | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pandas/core/common.py b/pandas/core/common.py index c86ee34f26d47..2607c9ad62456 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -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 # --------------------- # diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3f555c800d1eb..dca864cfe3515 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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 + 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") From a23e3241f900ab72c3e5d0bec9ea3da0b4bb500b Mon Sep 17 00:00:00 2001 From: Chang She Date: Thu, 29 Nov 2012 12:49:44 -0500 Subject: [PATCH 2/2] TST: check whether a repr_html is based on max cols/rows faking a qtconsole --- pandas/tests/test_format.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index 4b1978a9b8449..cb583f202fcf8 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -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")