From 3d4e48217ea707c330201527f090bd09358e28a0 Mon Sep 17 00:00:00 2001 From: Alex Barros Date: Mon, 8 Jan 2024 09:18:12 -0300 Subject: [PATCH] fix: formatters for timedelta missing listargs decoration (#1526) * test: add test for timedelta comparison report * fix: formatters timedelta missing decoration * fix: remove unused import --- src/ydata_profiling/profile_report.py | 2 -- src/ydata_profiling/report/formatters.py | 1 + tests/unit/test_comparison.py | 32 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/ydata_profiling/profile_report.py b/src/ydata_profiling/profile_report.py index fe07c73a4..79b94aa00 100644 --- a/src/ydata_profiling/profile_report.py +++ b/src/ydata_profiling/profile_report.py @@ -4,8 +4,6 @@ from pathlib import Path from typing import Any, Optional, Union -from PIL import Image - with warnings.catch_warnings(): warnings.simplefilter("ignore") import pkg_resources diff --git a/src/ydata_profiling/report/formatters.py b/src/ydata_profiling/report/formatters.py index 447565a06..8d12bff2c 100644 --- a/src/ydata_profiling/report/formatters.py +++ b/src/ydata_profiling/report/formatters.py @@ -219,6 +219,7 @@ def pluralize(count: Any, singular: str, plural: Optional[str] = None) -> str: return concatenate(result) +@list_args def fmt_timespan_timedelta( delta: Any, detailed: bool = False, max_units: int = 3, precision: int = 10 ) -> str: diff --git a/tests/unit/test_comparison.py b/tests/unit/test_comparison.py index ff2bb3442..748c5af12 100644 --- a/tests/unit/test_comparison.py +++ b/tests/unit/test_comparison.py @@ -68,3 +68,35 @@ def test_generate_comparison(): p2 = ProfileReport(df2, title="p1") html = p1.compare(p2).to_html() assert len(html) > 0 + + +def test_compare_timeseries(test_output_dir): + data = { + "feature_A": { + pd.Timestamp("2023-04-03 00:00:00"): 53321.6700520833, + pd.Timestamp("2023-04-03 01:00:00"): 53552.70312500002, + pd.Timestamp("2023-04-03 02:00:00"): 48905.89615885409, + pd.Timestamp("2023-04-03 03:00:00"): 46832.90592447904, + pd.Timestamp("2023-04-03 04:00:00"): 51819.66223958326, + } + } + + df1 = pd.DataFrame.from_dict(data) + df2 = pd.DataFrame.from_dict(data) + + latest_training_report = ProfileReport( + df1, + title="Report 1", + tsmode=True, + ) + production_training_report = ProfileReport( + df2, + title="Report 2", + tsmode=True, + ) + + comparison_report = compare([latest_training_report, production_training_report]) + output_file = test_output_dir / "comparison.html" + comparison_report.to_file(output_file) + assert (test_output_dir / "comparison.html").exists(), "Output file does not exist" + assert comparison_report is not None