[IPython-dev] HTML pandas issue (followup of twitter question)

Adam Hughes hughesadam87 at gmail.com
Tue Jul 29 13:22:16 EDT 2014


Thanks for answering my twitter question about HTML representations of
dataframes.  https://twitter.com/hughesadam87

I have a composition class that stores a DataFrame, and uses __getattr__ to
pass any attribute call down to the dataframe.  Therefore, my object has a
__repr__(), _repr_html_() etc...

The difference is, if I do "print obj.df", I get the nice html output by
default.  However, if I do "print obj", I don't get this; I get the
standard plain string output.  This is weird because I am not  overwriting
anything.  I can sucessfully get my object to print the dataframe html
representation by doing:

    from IPython.core.display import HTML
    display(HTML(obj.to_html()))

What I don't understand is how does the notebook know that a pandas
dataframe should display as html by default?  How are they communicating?
 When you print a dataframe, does the notebook look specifically for the
_repr_html  Since my object has all of the methods of a dataframe (although
not publicized), I imagine the notebook might be looking for certain
attributes or methods or something, to set this default HTML printing?

Hope that makes some sense, sorry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140729/6eab579e/attachment.html>


More information about the IPython-dev mailing list