Skip to content

Commit 2cea23a

Browse files
fix: timeseries gap comparison failing with no gaps for date index (ydataai#1551)
* fix: ts gap comparison failing with no gaps * fix(linting): code formatting --------- Co-authored-by: Azory YData Bot <azory@ydata.ai>
1 parent 98d0866 commit 2cea23a

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/ydata_profiling/expectations_report.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ def to_expectation_suite(
7979
if not data_context:
8080
data_context = ge.data_context.DataContext()
8181

82-
suite = data_context.add_expectation_suite(
83-
suite_name, overwrite_existing=True
84-
)
82+
suite = data_context.add_expectation_suite(suite_name, overwrite_existing=True)
8583

8684
# Instantiate an in-memory pandas dataset
8785
batch = ge.dataset.PandasDataset(self.df, expectation_suite=suite)

src/ydata_profiling/model/pandas/describe_timeseries_pandas.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,16 @@ def compute_gap_stats(series: pd.Series) -> pd.Series:
177177

178178
is_datetime = isinstance(series.index, pd.DatetimeIndex)
179179
gap_stats, gaps = identify_gaps(gap, is_datetime)
180+
has_gaps = len(gap_stats) > 0
180181

181182
stats = {
182-
"min": gap_stats.min(),
183-
"max": gap_stats.max(),
184-
"mean": gap_stats.mean(),
183+
"min": gap_stats.min() if has_gaps else 0,
184+
"max": gap_stats.max() if has_gaps else 0,
185+
"mean": gap_stats.mean() if has_gaps else 0,
185186
"std": gap_stats.std() if len(gap_stats) > 1 else 0,
186187
"series": series,
187188
"gaps": gaps,
189+
"n_gaps": len(gaps),
188190
}
189191
return stats
190192

src/ydata_profiling/report/structure/overview.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ def get_dataset_alerts(config: Settings, alerts: list) -> Alerts:
273273

274274

275275
def get_timeseries_items(config: Settings, summary: BaseDescription) -> Container:
276-
def format_tsindex_limit(limit: Any) -> str:
276+
@list_args
277+
def fmt_tsindex_limit(limit: Any) -> str:
277278
if isinstance(limit, datetime):
278279
return limit.strftime("%Y-%m-%d %H:%M:%S")
279280
else:
@@ -291,11 +292,11 @@ def format_tsindex_limit(limit: Any) -> str:
291292
},
292293
{
293294
"name": "Starting point",
294-
"value": format_tsindex_limit(summary.time_index_analysis.start),
295+
"value": fmt_tsindex_limit(summary.time_index_analysis.start),
295296
},
296297
{
297298
"name": "Ending point",
298-
"value": format_tsindex_limit(summary.time_index_analysis.end),
299+
"value": fmt_tsindex_limit(summary.time_index_analysis.end),
299300
},
300301
{
301302
"name": "Period",

src/ydata_profiling/report/structure/variables/render_timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _render_gap_tab(config: Settings, summary: dict) -> Container:
2828
{
2929
"name": "number of gaps",
3030
"value": fmt_numeric(
31-
len(summary["gap_stats"]["gaps"]), precision=config.report.precision
31+
summary["gap_stats"]["n_gaps"], precision=config.report.precision
3232
),
3333
},
3434
{

0 commit comments

Comments
 (0)