Skip to content

Commit

Permalink
Backport PR #25039: BUG: avoid usage in_qtconsole for recent IPython …
Browse files Browse the repository at this point in the history
…versions (#25054)
  • Loading branch information
meeseeksmachine authored and TomAugspurger committed Jan 31, 2019
1 parent 722bb79 commit e3634b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Bug Fixes

**Other**

-
- Fixed AttributeError when printing a DataFrame's HTML repr after accessing the IPython config object (:issue:`25036`)
-

.. _whatsnew_0.241.contributors:
Expand Down
13 changes: 10 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import itertools
import sys
import warnings
from distutils.version import LooseVersion
from textwrap import dedent

import numpy as np
Expand Down Expand Up @@ -646,9 +647,15 @@ def _repr_html_(self):
# XXX: In IPython 3.x and above, the Qt console will not attempt to
# display HTML, so this check can be removed when support for
# IPython 2.x is no longer needed.
if console.in_qtconsole():
# 'HTML output is disabled in QtConsole'
return None
try:
import IPython
except ImportError:
pass
else:
if LooseVersion(IPython.__version__) < LooseVersion('3.0'):
if console.in_qtconsole():
# 'HTML output is disabled in QtConsole'
return None

if self._info_repr():
buf = StringIO(u(""))
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import re
import sys
import textwrap
import warnings

import dateutil
Expand Down Expand Up @@ -2777,3 +2778,17 @@ def test_format_percentiles():
fmt.format_percentiles([2, 0.1, 0.5])
with pytest.raises(ValueError, match=msg):
fmt.format_percentiles([0.1, 0.5, 'a'])


def test_repr_html_ipython_config(ip):
code = textwrap.dedent("""\
import pandas as pd
df = pd.DataFrame({"A": [1, 2]})
df._repr_html_()
cfg = get_ipython().config
cfg['IPKernelApp']['parent_appname']
df._repr_html_()
""")
result = ip.run_cell(code)
assert not result.error_in_exec

0 comments on commit e3634b1

Please sign in to comment.