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

Conversation

TomAugspurger
Copy link
Contributor

Closes #7105

Before: http://nbviewer.ipython.org/gist/TomAugspurger/4c83a646ffb93d5ee978
After: http://nbviewer.ipython.org/gist/TomAugspurger/81bf15086864ca090bb6

After conosle:

In [28]: df
 Out[5]: 
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 2 columns):
0    2 non-null float64
1    2 non-null float64
dtypes: float64(2)

FYI, I don't know HTML, but I think this is mostly right.

@@ -485,7 +485,9 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this going to be very slow I think, maybe do this where the class is actually put their (if you know its html?).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, this is just info repr which is almost always short...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing a bit of profiling right now. I was hoping that adding the limit of 1 to .replace would only read the str until it replaces, and I think it might:

In [11]: s = 'abc' + 'S' + ('d' * 1000000)

In [12]: %timeit s.replace('S', 's')
10000 loops, best of 3: 145 µs per loop

In [13]: %timeit s.replace('S', 's', 1)
10000 loops, best of 3: 85.2 µs per loop

I'll have a bit more soon.

@jreback jreback added this to the 0.14.0 milestone May 13, 2014
@jreback
Copy link
Contributor

jreback commented May 13, 2014

rebase on master and you can merge this in when you are ready, I put up the display changes section: 8a8ead6

@TomAugspurger
Copy link
Contributor Author

Perf change vs. master

formating

Doesn't look like much. The x axis is the size of an NxN DataFrame of floats in log base 2.

@TomAugspurger
Copy link
Contributor Author

@jreback done. Will just wait on Travis.

@TomAugspurger
Copy link
Contributor Author

Merged via 2bb2a8d

@TomAugspurger TomAugspurger deleted the repr_html_info_class branch November 3, 2016 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: info _repr_html doesn't show class name
2 participants