Skip to content

Commit

Permalink
[MLC-379] fixed suite result display (#296)
Browse files Browse the repository at this point in the history
* Update deepchecks/base/display_suite.py
Co-authored-by: shir22 <33841818+shir22@users.noreply.github.com>
Co-authored-by: Matan Perlmutter <matan@deepchecks.com>
  • Loading branch information
yromanyshyn committed Dec 23, 2021
1 parent d8d4960 commit 59b5d7c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
4 changes: 3 additions & 1 deletion deepchecks/base/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ def show(self, show_conditions=True, unique_id=None):

def wrap_run(func, class_instance):
"""Wrap the run function of checks, and sets the `check` property on the check result."""

@wraps(func)
def wrapped(*args, **kwargs):
result = func(*args, **kwargs)
if not isinstance(result, CheckResult):
raise DeepchecksValueError(f'Check {class_instance.name()} expected to return CheckResult bot got: '
+ type(result).__name__)
result.check = class_instance
result.process_conditions()
return result
Expand Down
55 changes: 33 additions & 22 deletions deepchecks/base/display_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import sys
import tqdm
import pandas as pd

from IPython.core.display import display_html

from deepchecks import errors
from deepchecks.utils.strings import get_random_string
from deepchecks.base.check import CheckResult, CheckFailure
from deepchecks.base.display_pandas import dataframe_to_html, display_conditions_table
Expand Down Expand Up @@ -55,6 +55,10 @@ def get_display_exists_icon(exists: bool):

def display_suite_result(suite_name: str, results: List[Union[CheckResult, CheckFailure]]):
"""Display results of suite in IPython."""
if len(results) == 0:
display_html(f"""<h1>{suite_name}</h1><p>Suite is empty.</p>""", raw=True)
return

unique_id = get_random_string()
checks_with_conditions = []
display_table: List[CheckResult] = []
Expand All @@ -72,24 +76,42 @@ def display_suite_result(suite_name: str, results: List[Union[CheckResult, Check
msg = result.exception.__class__.__name__ + ': ' + str(result.exception)
name = result.check.name()
others_table.append([name, msg, 1])
else:
# Should never reach here!
raise errors.DeepchecksValueError(
f"Expecting list of 'CheckResult'|'CheckFailure', but got {type(result)}."
)

display_table = sorted(display_table, key=lambda it: it.priority)

light_hr = '<hr style="background-color: #eee;border: 0 none;color: #eee;height: 1px;">'
bold_hr = '<hr style="background-color: black;border: 0 none;color: black;height: 1px;">'

icons = """
<span style="color: green;display:inline-block">\U00002713</span> /
<span style="color: red;display:inline-block">\U00002716</span> /
<span style="color: orange;font-weight:bold;display:inline-block">\U00000021</span>
"""
html = f"""
<h1 id="summary_{unique_id}">{suite_name}</h1>
<p>The suite is composed of various checks such as: {get_first_3(results)}, etc...<br>
Each check may contain conditions (which results in {icons}), as well as other outputs such as plots or tables.<br>
Suites, checks and conditions can all be modified (see tutorial [link]).</p>
{bold_hr}<h2>Conditions Summary</h2>
"""
display_html(html, raw=True)

check_names = list(set(it.check.name() for it in results))
prologue = (
f"The suite is composed of various checks such as: {', '.join(check_names[:3])}, etc..."
if len(check_names) > 3
else f"The suite is composed of the following checks: {', '.join(check_names)}."
)

display_html(
f"""
<h1 id="summary_{unique_id}">{suite_name}</h1>
<p>{prologue}<br>
Each check may contain conditions (which results in {icons}),
as well as other outputs such as plots or tables.<br>
Suites, checks and conditions can all be modified (see tutorial [link]).</p>
{bold_hr}<h2>Conditions Summary</h2>
""",
raw=True
)

if checks_with_conditions:
display_conditions_table(checks_with_conditions, unique_id)
else:
Expand All @@ -113,16 +135,5 @@ def display_suite_result(suite_name: str, results: List[Union[CheckResult, Check
{dataframe_to_html(others_table.style.hide_index())}
"""
display_html(html, raw=True)
display_html(f'<br><a href="#summary_{unique_id}" style="font-size: 14px">Go to top</a>', raw=True)


def get_first_3(results: List[Union[CheckResult, CheckFailure]]):
first_3 = []
i = 0
while len(first_3) < 3 and i < len(results):
curr = results[i]
curr_name = curr.check.name()
if curr_name not in first_3:
first_3.append(curr_name)
i += 1
return ', '.join(first_3)

display_html(f'<br><a href="#summary_{unique_id}" style="font-size: 14px">Go to top</a>', raw=True)

0 comments on commit 59b5d7c

Please sign in to comment.