Skip to content

Commit

Permalink
fix: timeseries gap comparison failing with no gaps for date index (#…
Browse files Browse the repository at this point in the history
…1551)

* fix: ts gap comparison failing with no gaps

* fix(linting): code formatting

---------

Co-authored-by: Azory YData Bot <[email protected]>
  • Loading branch information
2 people authored and aquemy committed Feb 26, 2024
1 parent e0c770e commit bd5782b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/ydata_profiling/expectations_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def to_expectation_suite(
if not data_context:
data_context = ge.data_context.DataContext()

suite = data_context.add_expectation_suite(
suite_name, overwrite_existing=True
)
suite = data_context.add_expectation_suite(suite_name, overwrite_existing=True)

# Instantiate an in-memory pandas dataset
batch = ge.dataset.PandasDataset(self.df, expectation_suite=suite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,16 @@ def compute_gap_stats(series: pd.Series) -> pd.Series:

is_datetime = isinstance(series.index, pd.DatetimeIndex)
gap_stats, gaps = identify_gaps(gap, is_datetime)
has_gaps = len(gap_stats) > 0

stats = {
"min": gap_stats.min(),
"max": gap_stats.max(),
"mean": gap_stats.mean(),
"min": gap_stats.min() if has_gaps else 0,
"max": gap_stats.max() if has_gaps else 0,
"mean": gap_stats.mean() if has_gaps else 0,
"std": gap_stats.std() if len(gap_stats) > 1 else 0,
"series": series,
"gaps": gaps,
"n_gaps": len(gaps),
}
return stats

Expand Down
7 changes: 4 additions & 3 deletions src/ydata_profiling/report/structure/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ def get_dataset_alerts(config: Settings, alerts: list) -> Alerts:


def get_timeseries_items(config: Settings, summary: BaseDescription) -> Container:
def format_tsindex_limit(limit: Any) -> str:
@list_args
def fmt_tsindex_limit(limit: Any) -> str:
if isinstance(limit, datetime):
return limit.strftime("%Y-%m-%d %H:%M:%S")
else:
Expand All @@ -291,11 +292,11 @@ def format_tsindex_limit(limit: Any) -> str:
},
{
"name": "Starting point",
"value": format_tsindex_limit(summary.time_index_analysis.start),
"value": fmt_tsindex_limit(summary.time_index_analysis.start),
},
{
"name": "Ending point",
"value": format_tsindex_limit(summary.time_index_analysis.end),
"value": fmt_tsindex_limit(summary.time_index_analysis.end),
},
{
"name": "Period",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _render_gap_tab(config: Settings, summary: dict) -> Container:
{
"name": "number of gaps",
"value": fmt_numeric(
len(summary["gap_stats"]["gaps"]), precision=config.report.precision
summary["gap_stats"]["n_gaps"], precision=config.report.precision
),
},
{
Expand Down

0 comments on commit bd5782b

Please sign in to comment.