Skip to content

Commit da5f5eb

Browse files
TomAugspurgerjorisvandenbossche
authored andcommitted
BUG: avoid usage in_qtconsole for recent IPython versions (#25039)
* Drop IPython<4.0 compat * Revert "Drop IPython<4.0 compat" This reverts commit 0cb0452. * update a * whatsnew
1 parent 149138e commit da5f5eb

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

doc/source/whatsnew/v0.24.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Bug Fixes
8383

8484
**Other**
8585

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

8989
.. _whatsnew_0.241.contributors:

pandas/core/frame.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import itertools
1818
import sys
1919
import warnings
20+
from distutils.version import LooseVersion
2021
from textwrap import dedent
2122

2223
import numpy as np
@@ -646,9 +647,15 @@ def _repr_html_(self):
646647
# XXX: In IPython 3.x and above, the Qt console will not attempt to
647648
# display HTML, so this check can be removed when support for
648649
# IPython 2.x is no longer needed.
649-
if console.in_qtconsole():
650-
# 'HTML output is disabled in QtConsole'
651-
return None
650+
try:
651+
import IPython
652+
except ImportError:
653+
pass
654+
else:
655+
if LooseVersion(IPython.__version__) < LooseVersion('3.0'):
656+
if console.in_qtconsole():
657+
# 'HTML output is disabled in QtConsole'
658+
return None
652659

653660
if self._info_repr():
654661
buf = StringIO(u(""))

pandas/tests/io/formats/test_format.py

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import re
1414
import sys
15+
import textwrap
1516
import warnings
1617

1718
import dateutil
@@ -2777,3 +2778,17 @@ def test_format_percentiles():
27772778
fmt.format_percentiles([2, 0.1, 0.5])
27782779
with pytest.raises(ValueError, match=msg):
27792780
fmt.format_percentiles([0.1, 0.5, 'a'])
2781+
2782+
2783+
def test_repr_html_ipython_config(ip):
2784+
code = textwrap.dedent("""\
2785+
import pandas as pd
2786+
df = pd.DataFrame({"A": [1, 2]})
2787+
df._repr_html_()
2788+
2789+
cfg = get_ipython().config
2790+
cfg['IPKernelApp']['parent_appname']
2791+
df._repr_html_()
2792+
""")
2793+
result = ip.run_cell(code)
2794+
assert not result.error_in_exec

0 commit comments

Comments
 (0)