Description:
Starting with Pandas version 0.25.1, Mol objects within DataFrames are no longer drawn in a Jupyter notebook. The HTML string is displayed instead of the drawn molecule (<img src="data:image/png;base64,iVBORw0KGgoAAA...). With version 0.25.0 and below everything works fine.
Code to reproduce in a Jupyter Notebook:
from rdkit.Chem import PandasTools
df = PandasTools.LoadSDF('example.sdf')
df.head()
Current workaround aside from the switch to Pandas 0.25.0:
from rdkit.Chem import PandasTools
from IPython.core.display import HTML
def show(df):
return HTML(df.to_html(notebook=True))
df = PandasTools.LoadSDF('example.sdf')
show(df.head())
Confirmed. This is due to some change in pandas v0.25.x
Now we just need to figure out how to work around it.
Hi Greg,
the current workaround from above needs, at least in my hands, the following line:
PandasTools.RenderImagesInAllDataFrames(images=True)
Without that line, only a string gets displayed.
I looked at the Pandas code and they no longer call to_html from _repr_html_ but instead go directly to a "DataFrameFormatter". So, the patched to_html will not be called for repr. The best solution might be to patch the DataFrameFormatter.to_html() instead.
Or on second thought, that would probably be too harsh since it will patch every dataframe, not only the ones with structures.
So maybe patching _repr_html_ in addition to to_html?
Some additional info here, as I collect it:
from IPython.display import HTML;HTML(df.head().to_html())
Most helpful comment
Some additional info here, as I collect it:
from IPython.display import HTML;HTML(df.head().to_html())