Skip to content

Commit

Permalink
Fix/test hover (#1467)
Browse files Browse the repository at this point in the history
* fix hover for test adapter

* fix test name

* better test description

* fix
  • Loading branch information
mike0sv authored Feb 5, 2025
1 parent 4626756 commit 381a0ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/evidently/future/metric_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ def run(self, context: "Context", metric: "MetricCalculationBase", value: Metric
result: MetricTestResult = self.to_test()(context, metric, value)
if result.status == TestStatus.FAIL and not self.is_critical:
result.status = TestStatus.WARNING
metric_conf = metric.to_metric()
column = f" for {metric_conf.column}" if hasattr(metric_conf, "column") else ""
result.description = f"{metric_conf.__class__.__name__}{column}: {result.description}"
return result

def bind_single(self, fingerprint: Fingerprint) -> "BoundTest":
Expand Down
2 changes: 1 addition & 1 deletion src/evidently/ui/dashboards/test_suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_color(test, date) -> Optional[str]:
x=dates,
y=[1 for _ in range(len(dates))],
marker_color=[get_color(test, d) for d in dates],
hovertemplate=_get_test_hover(test.name, hover_params[test]),
hovertemplate=_get_test_hover(test, hover_params[test]),
customdata=[get_description(test, d) for i, d in enumerate(dates)],
showlegend=False,
)
Expand Down
14 changes: 12 additions & 2 deletions src/evidently/ui/dashboards/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,18 @@ def _hover_params_early_stop(obj: Any, paths: List[str]) -> Optional[List[Tuple[


def _get_hover_params(items: Set[TMT]) -> Dict[TMT, List[str]]:
from evidently.future.backport import TestV2Adapter

if len(items) == 0:
return {}
params: Dict[str, Dict[TMT, Set[str]]] = defaultdict(lambda: defaultdict(set))
for item in items:
for path, value in iterate_obj_fields(item, [], early_stop=_hover_params_early_stop):
item_fields = item
if isinstance(item, TestV2Adapter):
item_fields = item.test.test
for path, value in iterate_obj_fields(item_fields, [], early_stop=_hover_params_early_stop):
if path == "type":
continue
params[item.get_id()][item].add(f"{path}: {value}")
same_args: Dict[str, Set[str]] = {k: set.intersection(*v.values()) for k, v in params.items()}
return {
Expand All @@ -156,7 +163,10 @@ def _get_hover_params(items: Set[TMT]) -> Dict[TMT, List[str]]:
tests_colors_order = {ts: i for i, ts in enumerate(TEST_COLORS)}


def _get_test_hover(test_name: str, params: List[str]):
def _get_test_hover(test: Test, params: List[str]):
from evidently.future.backport import TestV2Adapter

test_name = test.test.test.__class__.__name__ if isinstance(test, TestV2Adapter) else test.name
params_join = "<br>".join(params)
hover = f"<b>Timestamp: %{{x}}</b><br><b>{test_name}</b><br>{params_join}<br>%{{customdata.description}}<br>"
return hover

0 comments on commit 381a0ea

Please sign in to comment.