Skip to content

BUG: Escape < and > in info _repr_html_ #7110

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
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
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ Bug Fixes
- Bug in ``MultiIndex.get_level_values`` doesn't preserve ``DatetimeIndex`` and ``PeriodIndex`` attributes (:issue:`7092`)
- Bug in ``Groupby`` doesn't preserve ``tz`` (:issue:`3950`)
- Bug in ``PeriodIndex`` partial string slicing (:issue:`6716`)
- Bug in the HTML repr of a truncated Series or DataFrame not showing the class name with the `large_repr` set to 'info'
(:issue:`7105`)

pandas 0.13.1
-------------
Expand Down
3 changes: 3 additions & 0 deletions doc/source/v0.14.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ API changes
Display Changes
~~~~~~~~~~~~~~~

- Fixed a bug in the HTML repr of a truncated Series or DataFrame not showing the class name with the
`large_repr` set to 'info' (:issue:`7105`)

.. _whatsnew_0140.groupby:

Groupby API Changes
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ def _repr_html_(self):
if self._info_repr():
buf = StringIO(u(""))
self.info(buf=buf)
return '<pre>' + buf.getvalue() + '</pre>'
# need to escape the <class>, should be the first line.
val = buf.getvalue().replace('<', r'&lt;', 1).replace('>',
r'&gt;', 1)
return '<pre>' + val + '</pre>'

if get_option("display.notebook_repr_html"):
max_rows = get_option("display.max_rows")
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def curpath():

def has_info_repr(df):
r = repr(df)
return r.split('\n')[0].startswith("<class")
c1 = r.split('\n')[0].startswith("<class")
c2 = r.split('\n')[0].startswith(r"&lt;class") # _repr_html_
return c1 or c2

def has_horizontally_truncated_repr(df):
r = repr(df)
Expand Down Expand Up @@ -1555,16 +1557,16 @@ def test_info_repr_html(self):
# Long
h, w = max_rows+1, max_cols-1
df = pandas.DataFrame(dict((k,np.arange(1,1+h)) for k in np.arange(w)))
assert '<class' not in df._repr_html_()
assert r'&lt;class' not in df._repr_html_()
with option_context('display.large_repr', 'info'):
assert '<class' in df._repr_html_()
assert r'&lt;class' in df._repr_html_()

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

def test_fake_qtconsole_repr_html(self):
def get_ipython():
Expand Down