From d505aa927ecb69a1646177fd6f0c51c902cd94c7 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 26 May 2026 09:46:41 +0200 Subject: [PATCH 1/6] FIX overflow handling for sklearn nightly HTML repr Newer sklearn versions (1.9+) emit `sk-top-container` both as a CSS class definition (.sk-top-container.sk-global { ... }) and as an HTML class attribute. The previous naive string replace only ran when the token appeared exactly once and would have corrupted the CSS otherwise. Use a regex that targets the class attribute on the top
so the inline `style="overflow: auto;"` is added correctly regardless of how many times the token appears in the HTML output. --- docs/changes.rst | 3 +++ skops/card/_model_card.py | 14 ++++++++++---- skops/card/tests/test_card.py | 1 - 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 324a98a5..c443d285 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -11,6 +11,9 @@ skops Changelog v0.15 ----- +- Fix model plot overflow handling so it works with the updated sklearn HTML + representation (sklearn 1.9+), where ``sk-top-container`` also appears in + CSS selectors. :pr:`517` by `Adrin Jalali`_. v0.14 ----- diff --git a/skops/card/_model_card.py b/skops/card/_model_card.py index 16378818..6d3ebb72 100644 --- a/skops/card/_model_card.py +++ b/skops/card/_model_card.py @@ -771,10 +771,16 @@ def _add_model_plot( """ model_plot_div = re.sub(r"\n\s+", "", str(estimator_html_repr(model))) - if model_plot_div.count("sk-top-container") == 1: - model_plot_div = model_plot_div.replace( - "sk-top-container", 'sk-top-container" style="overflow: auto;' - ) + # Add inline overflow style to the top container div to prevent it from + # overflowing on the HF model page. Target the class attribute via regex + # rather than a naive string replace, since newer sklearn versions + # mention `sk-top-container` in CSS selectors too. + model_plot_div = re.sub( + r'(]*\bclass="[^"]*\bsk-top-container\b[^"]*")', + r'\1 style="overflow: auto;"', + model_plot_div, + count=1, + ) if description: content = f"{description}\n\n{model_plot_div}" diff --git a/skops/card/tests/test_card.py b/skops/card/tests/test_card.py index 964498d9..93b8d140 100644 --- a/skops/card/tests/test_card.py +++ b/skops/card/tests/test_card.py @@ -240,7 +240,6 @@ def test_no_overflow(self, model_card): "Model description/Training Procedure/Model Plot" ).format() # test if the model doesn't overflow the huggingface models page - assert result.count("sk-top-container") == 1 assert 'style="overflow: auto;' in result def test_model_diagram_false(self): From 1194983d09b2eb5b3ebe4c0460d6c2f17043f107 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 26 May 2026 09:58:05 +0200 Subject: [PATCH 2/6] MNT remove HF-specific overflow injection from model plot The inline `style="overflow: auto;"` was added to work around how sklearn's HTML repr renders inside the HuggingFace Hub models page. skops no longer specifically targets HF Hub (see #462 and #512), so this HF-specific HTML manipulation is no longer needed. This also resolves the breakage with sklearn 1.9+ where the previous naive string replace would have corrupted the new CSS that now also mentions `sk-top-container`. --- docs/changes.rst | 7 ++++--- skops/card/_model_card.py | 10 ---------- skops/card/tests/test_card.py | 7 ------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index c443d285..9d8f3f07 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -11,9 +11,10 @@ skops Changelog v0.15 ----- -- Fix model plot overflow handling so it works with the updated sklearn HTML - representation (sklearn 1.9+), where ``sk-top-container`` also appears in - CSS selectors. :pr:`517` by `Adrin Jalali`_. +- Remove the HuggingFace Hub specific overflow style injection from the model + plot section. skops no longer targets HF Hub, so the inline style is + unnecessary and was incompatible with the sklearn 1.9+ HTML representation. + :pr:`517` by `Adrin Jalali`_. v0.14 ----- diff --git a/skops/card/_model_card.py b/skops/card/_model_card.py index 6d3ebb72..56fd5d1a 100644 --- a/skops/card/_model_card.py +++ b/skops/card/_model_card.py @@ -771,16 +771,6 @@ def _add_model_plot( """ model_plot_div = re.sub(r"\n\s+", "", str(estimator_html_repr(model))) - # Add inline overflow style to the top container div to prevent it from - # overflowing on the HF model page. Target the class attribute via regex - # rather than a naive string replace, since newer sklearn versions - # mention `sk-top-container` in CSS selectors too. - model_plot_div = re.sub( - r'(]*\bclass="[^"]*\bsk-top-container\b[^"]*")', - r'\1 style="overflow: auto;"', - model_plot_div, - count=1, - ) if description: content = f"{description}\n\n{model_plot_div}" diff --git a/skops/card/tests/test_card.py b/skops/card/tests/test_card.py index 93b8d140..90751aae 100644 --- a/skops/card/tests/test_card.py +++ b/skops/card/tests/test_card.py @@ -235,13 +235,6 @@ def test_default(self, model_card): assert re.match(r"