Skip to content

Commit 2bb2a8d

Browse files
author
TomAugspurger
committed
BUG: Escape < and > in info _repr_html_
Closes #7105
1 parent d505d23 commit 2bb2a8d

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ Bug Fixes
501501
- Bug in ``MultiIndex.get_level_values`` doesn't preserve ``DatetimeIndex`` and ``PeriodIndex`` attributes (:issue:`7092`)
502502
- Bug in ``Groupby`` doesn't preserve ``tz`` (:issue:`3950`)
503503
- Bug in ``PeriodIndex`` partial string slicing (:issue:`6716`)
504+
- Bug in the HTML repr of a truncated Series or DataFrame not showing the class name with the `large_repr` set to 'info'
505+
(:issue:`7105`)
504506

505507
pandas 0.13.1
506508
-------------

doc/source/v0.14.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ Display Changes
204204

205205
- Regression in the display of a MultiIndexed Series with ``display.max_rows`` is less than the
206206
length of the series (:issue:`7101`)
207+
- Fixed a bug in the HTML repr of a truncated Series or DataFrame not showing the class name with the
208+
`large_repr` set to 'info' (:issue:`7105`)
207209

208210
.. _whatsnew_0140.groupby:
209211

pandas/core/frame.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,10 @@ def _repr_html_(self):
485485
if self._info_repr():
486486
buf = StringIO(u(""))
487487
self.info(buf=buf)
488-
return '<pre>' + buf.getvalue() + '</pre>'
488+
# need to escape the <class>, should be the first line.
489+
val = buf.getvalue().replace('<', r'&lt;', 1).replace('>',
490+
r'&gt;', 1)
491+
return '<pre>' + val + '</pre>'
489492

490493
if get_option("display.notebook_repr_html"):
491494
max_rows = get_option("display.max_rows")

pandas/tests/test_format.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def curpath():
3434

3535
def has_info_repr(df):
3636
r = repr(df)
37-
return r.split('\n')[0].startswith("<class")
37+
c1 = r.split('\n')[0].startswith("<class")
38+
c2 = r.split('\n')[0].startswith(r"&lt;class") # _repr_html_
39+
return c1 or c2
3840

3941
def has_horizontally_truncated_repr(df):
4042
r = repr(df)
@@ -1555,16 +1557,16 @@ def test_info_repr_html(self):
15551557
# Long
15561558
h, w = max_rows+1, max_cols-1
15571559
df = pandas.DataFrame(dict((k,np.arange(1,1+h)) for k in np.arange(w)))
1558-
assert '<class' not in df._repr_html_()
1560+
assert r'&lt;class' not in df._repr_html_()
15591561
with option_context('display.large_repr', 'info'):
1560-
assert '<class' in df._repr_html_()
1562+
assert r'&lt;class' in df._repr_html_()
15611563

15621564
# Wide
15631565
h, w = max_rows-1, max_cols+1
15641566
df = pandas.DataFrame(dict((k,np.arange(1,1+h)) for k in np.arange(w)))
15651567
assert '<class' not in df._repr_html_()
15661568
with option_context('display.large_repr', 'info'):
1567-
assert '<class' in df._repr_html_()
1569+
assert '&lt;class' in df._repr_html_()
15681570

15691571
def test_fake_qtconsole_repr_html(self):
15701572
def get_ipython():

0 commit comments

Comments
 (0)