diff --git a/skbase/base/_pretty_printing/_object_html_repr.py b/skbase/base/_pretty_printing/_object_html_repr.py index 1c4fc017..d5a7ee68 100644 --- a/skbase/base/_pretty_printing/_object_html_repr.py +++ b/skbase/base/_pretty_printing/_object_html_repr.py @@ -61,6 +61,51 @@ 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 (
+        '
' + f'{escaped_name}{value_str}
' + "" + "" + "".join(rows) + "" + "
ParameterValue
" + ) + + def _write_label_html( out, name, @@ -68,9 +113,11 @@ 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'
') + out.write(f"
") + out.write(f'
') name = html.escape(name) if name_details is not None: @@ -79,12 +126,30 @@ 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'
' + f"
{name_details}
" + ) + else: + dropdown_content = ( + f'
{name_details}
' + ) + out.write( '' f"" - f'
{name_details}'
-            "
" + f"{dropdown_content}" ) else: out.write(f"") @@ -133,7 +198,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 +221,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 +234,7 @@ def _write_base_object_html( outer_class="sk-item", inner_class="sk-estimator", checked=first_call, + estimator=single_estimator, ) @@ -335,6 +412,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