From 7938ce21e19b0a6e42834cbcc68f9749af1061e4 Mon Sep 17 00:00:00 2001 From: AnimeshPatra2005 Date: Thu, 26 Feb 2026 22:41:59 +0530 Subject: [PATCH 1/5] ENH: update html parameter display to match scikit-learn style --- .../_pretty_printing/_object_html_repr.py | 108 +++++++++++++++++- 1 file changed, 105 insertions(+), 3 deletions(-) diff --git a/skbase/base/_pretty_printing/_object_html_repr.py b/skbase/base/_pretty_printing/_object_html_repr.py index 1c4fc017..d90b272f 100644 --- a/skbase/base/_pretty_printing/_object_html_repr.py +++ b/skbase/base/_pretty_printing/_object_html_repr.py @@ -61,6 +61,50 @@ def _sk_visual_block_(self): return self +def _params_to_html_table(estimator): + """Generate an HTML parameter table for an estimator. + + Instead of showing a raw ``str(estimator)`` inside a ``
`` block,
+    this function builds a two-column HTML table: one column for the
+    parameter name and one for its current value.
+
+    Parameters
+    ----------
+    estimator : BaseObject
+        The estimator whose ``get_params(deep=False)`` will be used.
+
+    Returns
+    -------
+    str
+        HTML string of a ```` element, or empty string when the
+        estimator has no parameters or no ``get_params`` method.
+    """
+    if not hasattr(estimator, "get_params"):
+        return ""
+
+    params = estimator.get_params(deep=False)
+    if not params:
+        return "No parameters"
+
+    rows = []
+    for param_name, value in sorted(params.items()):
+        value_str = html.escape(repr(value))
+        escaped_name = html.escape(param_name)
+        rows.append(
+            f""
+            f''
+            f''
+            f""
+        )
+
+    return (
+        '
{escaped_name}{value_str}
' + "" + "" + "".join(rows) + "" + "
ParameterValue
" + ) + + def _write_label_html( out, name, @@ -68,6 +112,7 @@ def _write_label_html( outer_class="sk-label-container", inner_class="sk-label", checked=False, + estimator=None, ): """Write labeled html with or without a dropdown with named details.""" out.write(f'
') @@ -79,12 +124,29 @@ def _write_label_html( checked_str = "checked" if checked else "" est_id = uuid.uuid4() + + # Show a structured param table when possible; fall back to
.
+        if estimator is not None and hasattr(estimator, "get_params"):
+            table_html = _params_to_html_table(estimator)
+            if table_html:
+                dropdown_content = (
+                    '
' + f"{table_html}
" + ) + else: + dropdown_content = ( + f'
{name_details}
' + ) + else: + dropdown_content = ( + f'
{name_details}
' + ) + out.write( '' f"" - f'
{name_details}'
-            "
" + f"{dropdown_content}" ) else: out.write(f"") @@ -133,7 +195,12 @@ def _write_base_object_html( out.write(f'
') if base_object_label: - _write_label_html(out, base_object_label, base_object_label_details) + _write_label_html( + out, + base_object_label, + base_object_label_details, + estimator=base_object, + ) kind = est_block.kind out.write(f'
') @@ -151,6 +218,12 @@ def _write_base_object_html( out.write("
") elif est_block.kind == "single": + # Only pass an estimator when it has get_params; strings/None don't. + single_estimator = ( + est_block.estimators + if hasattr(est_block.estimators, "get_params") + else None + ) _write_label_html( out, est_block.names, @@ -158,6 +231,7 @@ def _write_base_object_html( outer_class="sk-item", inner_class="sk-estimator", checked=first_call, + estimator=single_estimator, ) @@ -335,6 +409,34 @@ def _write_base_object_html( #$id div.sk-text-repr-fallback { display: none; } +#$id .sk-toggleable__content-table { + padding: 0.4em; + background-color: #f0f8ff; +} +#$id table.sk-params-table { + border-collapse: collapse; + font-family: monospace; + font-size: 0.9em; + width: 100%; +} +#$id table.sk-params-table thead tr { + background-color: #d4ebff; +} +#$id table.sk-params-table th, +#$id table.sk-params-table td { + padding: 0.3em 0.6em; + text-align: left; + border: 1px solid gray; +} +#$id table.sk-params-table tbody tr:nth-child(even) { + background-color: #e8f4ff; +} +#$id table.sk-params-table tbody tr:hover { + background-color: #d4ebff; +} +#$id .sk-param-name { + font-weight: bold; +} """.replace(" ", "").replace("\n", "") # noqa From 36dbd4e164ee6d3aaeac97019b1ef87d28e0dc7d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Feb 2026 17:25:31 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- skbase/base/_pretty_printing/_object_html_repr.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/skbase/base/_pretty_printing/_object_html_repr.py b/skbase/base/_pretty_printing/_object_html_repr.py index d90b272f..c31737b3 100644 --- a/skbase/base/_pretty_printing/_object_html_repr.py +++ b/skbase/base/_pretty_printing/_object_html_repr.py @@ -134,9 +134,7 @@ def _write_label_html( f"{table_html}
" ) else: - dropdown_content = ( - f'
{name_details}
' - ) + dropdown_content = f'
{name_details}
' else: dropdown_content = ( f'
{name_details}
' From b83a5b2cd637180772e01b9fb8a0bcb988621744 Mon Sep 17 00:00:00 2001 From: AnimeshPatra2005 Date: Wed, 25 Mar 2026 15:43:59 +0530 Subject: [PATCH 3/5] style: fix spacing in _object_html_repr --- skbase/base/_pretty_printing/_object_html_repr.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/skbase/base/_pretty_printing/_object_html_repr.py b/skbase/base/_pretty_printing/_object_html_repr.py index c31737b3..1d3cb9ad 100644 --- a/skbase/base/_pretty_printing/_object_html_repr.py +++ b/skbase/base/_pretty_printing/_object_html_repr.py @@ -74,7 +74,7 @@ def _params_to_html_table(estimator): The estimator whose ``get_params(deep=False)`` will be used. Returns - ------- + str HTML string of a ```` element, or empty string when the estimator has no parameters or no ``get_params`` method. @@ -92,7 +92,8 @@ def _params_to_html_table(estimator): escaped_name = html.escape(param_name) rows.append( f"" - f'' + f'' f'' f"" ) @@ -115,7 +116,8 @@ def _write_label_html( estimator=None, ): """Write labeled html with or without a dropdown with named details.""" - out.write(f'
') + out.write(f'
') + out.write(f'
') name = html.escape(name) if name_details is not None: @@ -134,7 +136,10 @@ def _write_label_html( f"{table_html}
" ) else: - dropdown_content = f'
{name_details}
' + dropdown_content = ( + f'
' + f'
{name_details}
' + ) else: dropdown_content = ( f'
{name_details}
' From 16ece732db54d03bc10cc34a04ad5e136de45bbd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 25 Mar 2026 10:18:16 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- skbase/base/_pretty_printing/_object_html_repr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skbase/base/_pretty_printing/_object_html_repr.py b/skbase/base/_pretty_printing/_object_html_repr.py index 1d3cb9ad..870a9770 100644 --- a/skbase/base/_pretty_printing/_object_html_repr.py +++ b/skbase/base/_pretty_printing/_object_html_repr.py @@ -74,7 +74,7 @@ def _params_to_html_table(estimator): The estimator whose ``get_params(deep=False)`` will be used. Returns - + str HTML string of a ``
{escaped_name}' + f'{escaped_name}{value_str}
`` element, or empty string when the estimator has no parameters or no ``get_params`` method. @@ -116,7 +116,7 @@ def _write_label_html( estimator=None, ): """Write labeled html with or without a dropdown with named details.""" - out.write(f'
') + out.write(f"
") out.write(f'
') name = html.escape(name) @@ -138,7 +138,7 @@ def _write_label_html( else: dropdown_content = ( f'
' - f'
{name_details}
' + f"
{name_details}
" ) else: dropdown_content = ( From e28737b67c6b86c480bfcc9c475fefb3989fd953 Mon Sep 17 00:00:00 2001 From: AnimeshPatra2005 Date: Wed, 25 Mar 2026 16:01:42 +0530 Subject: [PATCH 5/5] style: fix missing dashes under Returns in docstring --- skbase/base/_pretty_printing/_object_html_repr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skbase/base/_pretty_printing/_object_html_repr.py b/skbase/base/_pretty_printing/_object_html_repr.py index 870a9770..d5a7ee68 100644 --- a/skbase/base/_pretty_printing/_object_html_repr.py +++ b/skbase/base/_pretty_printing/_object_html_repr.py @@ -74,7 +74,7 @@ def _params_to_html_table(estimator): The estimator whose ``get_params(deep=False)`` will be used. Returns - + ------- str HTML string of a ``
`` element, or empty string when the estimator has no parameters or no ``get_params`` method.