diff --git a/narwhals/_utils.py b/narwhals/_utils.py index 601bf9a0ef..5a1391a587 100644 --- a/narwhals/_utils.py +++ b/narwhals/_utils.py @@ -1544,6 +1544,49 @@ def generate_repr(header: str, native_repr: str) -> str: ) +# NOTE: Unsure on how to test this reliably +def generate_repr_html( + caption_text: Literal["Narwhals DataFrame", "Narwhals LazyFrame", "Narwhals Series"], + /, + native_html: str, +) -> str | None: # pragma: no cover + if caption_text == "Narwhals LazyFrame" and "LazyFrame" in native_html: + html = native_html.replace("LazyFrame", "LazyFrame.to_native()") + return f"{html}
{caption_text}
" + import io + import xml.etree.ElementTree as ET + + style_css = ( + ".dataframe caption { " + "caption-side: top; " + "text-align: center; " + "font-weight: bold; " + "padding-top: 8px;" + "}" + ) + try: + tree = ET.parse(io.StringIO(native_html.replace("