Skip to content

Commit

Permalink
Fix duplications report metrics when report run multiple times. (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liraim authored Jul 31, 2024
1 parent 4e4f6b0 commit b958d9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/evidently/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def run(
self.timestamp = self._timestamp
else:
self.timestamp = timestamp or datetime.now()
self._first_level_metrics = []
self._inner_suite.reset()
self._inner_suite.set_engine(PythonEngine() if engine is None else engine())

Expand Down
23 changes: 15 additions & 8 deletions tests/report/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import List

import pandas as pd
import pytest

from evidently.base_metric import InputData
from evidently.base_metric import Metric
Expand Down Expand Up @@ -35,14 +34,9 @@ def render_html(self, obj) -> List[BaseWidgetInfo]:
raise NotImplementedError


@pytest.fixture
def report():
def test_as_dict():
report = Report(metrics=[MockMetric()])
report.run(reference_data=pd.DataFrame(), current_data=pd.DataFrame())
return report


def test_as_dict(report: Report):
assert report.as_dict() == {"metrics": [{"metric": "MockMetric", "result": {"value": "a"}}]}
include_series = report.as_dict(include={"MockMetric": {"value", "series"}})["metrics"][0]["result"]
assert "series" in include_series
Expand All @@ -54,7 +48,20 @@ def test_as_dict(report: Report):
assert "distribution" in include_render


def test_json(report: Report):
def test_json():
report = Report(metrics=[MockMetric()])
report.run(reference_data=pd.DataFrame(), current_data=pd.DataFrame())
default = json.loads(report.json())["metrics"]
assert default == [{"metric": "MockMetric", "result": {"value": "a"}}]

include_series = json.loads(report.json(include={"MockMetric": {"value", "series"}}))["metrics"]
assert include_series == [{"metric": "MockMetric", "result": {"value": "a", "series": [0]}}]


def test_multirun_json():
report = Report(metrics=[MockMetric()])
report.run(reference_data=pd.DataFrame(), current_data=pd.DataFrame())
report.run(reference_data=pd.DataFrame(), current_data=pd.DataFrame()) # 2nd run to check that report isn't changed
default = json.loads(report.json())["metrics"]
assert default == [{"metric": "MockMetric", "result": {"value": "a"}}]

Expand Down

0 comments on commit b958d9a

Please sign in to comment.