-
Notifications
You must be signed in to change notification settings - Fork 845
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
Fixes #5017 #5103
Fixes #5017 #5103
Conversation
The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@ptosco : I merged this without actually trying it, and it doesn't seem to actually work in jupyter: Which version/OS did you test this on? |
The same problem occurs with pandas 1.4.2 |
@greglandrum The fix works, the problem is that I inadvertently reverted it in PR #5132: |
@ptosco : sorry, I should have caught that in the review... the PandasTools code is a real brain bender though. It would be super shiny if we could figure out some way to actually automatically test this stuff, but I don't see how that would work. |
Reference Issue
This PR fixes #5017
What does this implement/fix? Explain your changes.
patchPandasrepr()
patchespd.io.formats.html.HTMLFormatter._write_cell()
, then it restores the original function before returning. However, while doing so, it also sets an_rdkitpatched
attribute onpandas.io.formats.html.HTMLFormatter
.The next time patchPandasrepr() is called, the patch is not applied anymore due to the present of the
_rdkitpatched
attribute, even though the patch has actually been reverted.This explains why the DataFrame displays molecules as PNG images only the first time.
The fix is removing the usage of
_rdkitpatched
attribute entirely as it is not necessary, since the patch is applied and then reverted. Instead, atry..finally
block is used to make sure that the patch is reverted before returning even if an exception is raised.After this PR, running the test described in #5017 yields the desired behavior: