0

I’d been using AddMoleculeColumnToFrame on Google Colab with no problem. After not using it for about 1 month I just discovered that it stopped working, i.e. the images are not showing up in the data frame (see below).

Any ideas? The most likely explanation is that something changed on Google Colab. But could it also be that a new version of Pandas is causing the problem?

Here’s the link to the notebook and a screenshot.

https://colab.research.google.com/drive/1nQPmdEbYQgVsFr7c44yRd3wpXPEsJar3

enter image description here

Jan Jensen
  • 133
  • 4

1 Answers1

2

Seems like this is a problem with all pandas versions above 0.25.0, So I guess for now the easiest fix is to downgrade pandas. Or you can use this method which seemed to work for me:

from IPython.display import HTML
HTML(df.to_html())

https://colab.research.google.com/drive/1eP8VZdr61DIoYXRz3PfwmVeG71GRzsRG

I am not quite sure why but this also seems to work:

def display_mol(x):
    if isinstance(x, Mol):
        return x
    return x

df.style.format(display_mol)

Screenshot: enter image description here

Oliver Scott
  • 1,673
  • 8
  • 17
  • The notebook doesn't work for me: I get "name 'Mol' is not defined". I also couldn't get HTML(df.to_html()) to work. Can you give an example? Finally, I tried downgrading pandas, but it always seems to use the same version even if you redefine the sys.path order. Any help is appreciated – Jan Jensen Nov 05 '19 at 10:19
  • For the first problem I forgot to add the import: `from rdkit.Chem import Mol`. As for the HTML method this seems to work fine for me, I'll take another look though. – Oliver Scott Nov 05 '19 at 10:37
  • HTML(df.to_html()) now works. I have no idea why it didn't work before. Thank you very much! I really appreciate the help. Btw do you have any ideas on how to downgrade pandas? I've tried to install 0.24.2 using both pip and conda-forge but the import always uses /usr/local/lib/python3.6/dist-packages/pandas/__init__.py no matter even if it comes later in the path – Jan Jensen Nov 05 '19 at 11:15
  • I had a go at downgrading pandas in colab and I realise that this isn't particularly easy. Although I did eventually get it to work, it isn't particularly intuitive. In a new notebook I did: `!pip install pandas==0.24.2` followed by restarting the runtime, I then downloaded rdkit in the same way as before, restarted the runtime again, and now pandas seems to stay on version 0.24.2. After this I used the same code as above and the images show as expected. – Oliver Scott Nov 05 '19 at 14:14
  • ^ [colab](https://colab.research.google.com/drive/1d4GDh6cth3N6zJoondoTnGWHUXzG_e2Z) – Oliver Scott Nov 05 '19 at 14:15
  • Genius! Thanks so much! – Jan Jensen Nov 05 '19 at 18:17