Skip to content

Re-unify execution paths for to_html() and _repr_html_() #30727

Open
@greglandrum

Description

@greglandrum

The changes associated with #27991 (merged as part of v0.25.1) changed the behavior of DataFrame._repr_html_()

We use monkey patching to allow the automatic display (within Jupyter notebooks) of chemical structures stored in DataFrames as part of the RDKit project. Given how useful it is to be able to automatically render specialized data types in DataFrames, I would assume we're not the only ones doing this. For those who are interested, here's an example from the RDKit community demonstrating what this looks like - https://www.blopig.com/blog/2017/02/using-rdkit-to-load-ligand-sdfs-into-pandas-dataframes/

Previous to v0.25.1 we could simply monkey patch DataFrame.to_html() since it was called by DataFrame._repr_html_(), but now it looks like we need to patch both methods. Doing this kind of patching is always a bit fraught and having to do it twice really seems to be begging for support problems down the road. Note: A single patch to DataFrameFormatter.to_html() would also be possible, but it looks like that would make it impossible to for us to disable the specialized rendering on a DataFrame by DataFrame basis.

I'm happy to submit a PR with a fix if the maintainers agree that re-unifying these two is desirable.

I think this should probably be classified as a Cleanup item, but I didn't want to presume.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO HTMLread_html, to_html, Styler.apply, Styler.applymapRefactorInternal refactoring of code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions