Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] fix html display for meta-objects #160

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions skbase/base/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from inspect import isclass
from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Tuple, Union, overload

from sklearn.utils._estimator_html_repr import _VisualBlock

from skbase.base._base import BaseEstimator, BaseObject
from skbase.base._pretty_printing._object_html_repr import _VisualBlock
from skbase.utils._iter import _format_seq_to_str, make_strings_unique
from skbase.validate import is_named_object_tuple

Expand Down Expand Up @@ -657,8 +656,9 @@ def concat(x, y):
def _sk_visual_block_(self):
"""Logic to help render meta estimator as visual HTML block."""
# Use tag interface that will be available when mixin is used
named_object_attr = self.get_tag("named_object_parameters") # type: ignore
named_objects = getattr(self, named_object_attr)
named_object_attr_name = self.get_tag("named_object_parameters") # type: ignore
named_object_attr = getattr(self, named_object_attr_name)
named_objects = self._coerce_to_named_object_tuples(named_object_attr)
_, objs = self._get_names_and_objects(named_objects)

def _get_name(name, obj):
Expand All @@ -667,7 +667,7 @@ def _get_name(name, obj):
# Is an estimator
return f"{name}: {obj.__class__.__name__}"

names = [_get_name(name, est) for name, est in self.steps]
names = [_get_name(name, est) for name, est in named_objects]
name_details = [str(obj) for obj in objs]
return _VisualBlock(
"serial",
Expand Down
4 changes: 2 additions & 2 deletions skbase/base/_pretty_printing/_object_html_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import html
import uuid
from contextlib import closing, suppress
from contextlib import closing
from io import StringIO
from string import Template

Expand Down Expand Up @@ -91,7 +91,7 @@ def _write_label_html(

def _get_visual_block(base_object):
"""Generate information about how to display a BaseObject."""
with suppress(AttributeError):
if hasattr(base_object, "_sk_visual_block_"):
return base_object._sk_visual_block_()

if isinstance(base_object, str):
Expand Down