Rdkit: Mol rendering within DataFrames in a Jupyter Notebook is broken with Pandas 0.25.1

Created on 1 Oct 2019  路  5Comments  路  Source: rdkit/rdkit

Description:


  • Python Version: 3.7.4
  • RDKit Version: 2019.03.4
  • Pandas Version: 0.25.1
  • Platform: macOS/Linux


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())

bug

Most helpful comment

Some additional info here, as I collect it:

All 5 comments

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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lpenguin picture lpenguin  路  5Comments

mc-robinson picture mc-robinson  路  5Comments

rvianello picture rvianello  路  3Comments

xjalencas picture xjalencas  路  5Comments

RobinFrcd picture RobinFrcd  路  4Comments