Skip to content

Commit

Permalink
fix: comparison alerts (#1229)
Browse files Browse the repository at this point in the history
* fix: compare fail if alerts are not in all reports
  • Loading branch information
alexbarros authored and aquemy committed Jan 2, 2023
1 parent 09ccae6 commit 6f6baf2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/pandas_profiling/compare_reports.py
Expand Up @@ -220,6 +220,30 @@ def _apply_config(description: dict, config: Settings) -> dict:
return description


def _is_alert_present(alert, alert_list):
for a in alert_list:
if a.column_name == alert.column_name and a.alert_type == alert.alert_type:
return True
return False


def _create_placehoder_alerts(report_alerts: tuple) -> tuple:
from copy import copy

fixed = [[] for _ in report_alerts]
for idx, alerts in enumerate(report_alerts):
for alert in alerts:
fixed[idx].append(alert)
for i, fix in enumerate(fixed):
if i == idx:
continue
if not _is_alert_present(alert, report_alerts[i]):
empty_alert = copy(alert)
empty_alert._is_empty = True
fix.append(empty_alert)
return tuple(fixed)


def compare(
reports: List[ProfileReport],
config: Optional[Settings] = None,
Expand Down Expand Up @@ -279,7 +303,7 @@ def compare(
res = _update_merge(res, r)

res["analysis"]["title"] = _compare_title(res["analysis"]["title"])

res["alerts"] = _create_placehoder_alerts(res["alerts"])
profile = ProfileReport(None, config=_config)
profile._description_set = res
return profile
2 changes: 2 additions & 0 deletions src/pandas_profiling/model/alerts.py
Expand Up @@ -80,6 +80,7 @@ def __init__(
values: Optional[Dict] = None,
column_name: Optional[str] = None,
fields: Optional[Set] = None,
is_empty: bool = False,
):
if values is None:
values = {}
Expand All @@ -90,6 +91,7 @@ def __init__(
self.alert_type = alert_type
self.values = values
self.column_name = column_name
self._is_empty = is_empty

@property
def alert_type_name(self) -> str:
Expand Down
Expand Up @@ -16,7 +16,7 @@
<tr{% if loop.first %} style="border-top:0"{% endif %}>
{% for alert in value %}
<td>
{% if alert is not none %}
{% if not alert._is_empty %}
{% include 'alerts/alert_' + alert.alert_type.name | lower + '.html' %}
{% else %}
<em>Alert not present in {{ style._labels[idx] }}</em>
Expand Down

0 comments on commit 6f6baf2

Please sign in to comment.