Skip to main content
Version: Next

ts_shape.events.quality.data_gap_analysis

Classes
NameDescription
DataGapAnalysisEventsQuality: Data Gap Analysis

DataGapAnalysisEvents​

classsource
DataGapAnalysisEvents(
dataframe: pd.DataFrame,
signal_uuid: str,
*,
event_uuid: str = "quality:data_gap",
value_column: str = "value_double",
time_column: str = "systime"
) -> None

Bases: Base

Quality: Data Gap Analysis

Answer the question "where are the holes in my data?" by analyzing gaps in a numeric signal's timestamps. Complements :class:SignalQualityEvents (which detects individual missing-data events) with pattern-level analysis: gap summaries, per-period coverage, and interpolation-candidate identification.

Methods:

  • detect_gaps: Locate all gaps longer than a threshold.
  • gap_summary: Aggregate statistics across all gaps.
  • coverage_by_period: Data coverage percentage per time window.
  • interpolation_candidates: Gaps small enough to interpolate safely.
Functions
NameDescription
detect_gapsLocate all gaps longer than min_gap.
gap_summaryAggregate statistics across all gaps.
coverage_by_periodData coverage percentage per time window.
interpolation_candidatesIdentify gaps small enough to safely interpolate.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
signal_uuidstrUUID of the signal to analyze.required
event_uuidstrUUID stamped on emitted events.'quality:data_gap'
value_columnstrColumn holding the signal values.'value_double'
time_columnstrTimestamp column.'systime'

detect_gaps​

methodsource
detect_gaps(min_gap: str | pd.Timedelta | None = None) -> pd.DataFrame

Locate all gaps longer than min_gap.

A gap is a step between two consecutive samples strictly longer than min_gap: regular 10-minute sampling with min_gap="10min" has no gaps.

Parameters
NameTypeDescriptionDefault
min_gapstr | Timedelta | NoneGap threshold (e.g. '5s', '1min', '1h'). None (default) is twice the median positive sampling interval, the rule of :meth:coverage_by_period, so a regularly sampled signal has no gaps. A zero-length step (duplicate timestamp) is never a gap, even with min_gap="0s".None
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, gap_duration_seconds, samples_before_gap,
DataFramesamples_after_gap. gap_duration_seconds equals
DataFrameduration_seconds.

gap_summary​

methodsource
gap_summary(min_gap: str | pd.Timedelta | None = None) -> pd.DataFrame

Aggregate statistics across all gaps.

Parameters
NameTypeDescriptionDefault
min_gapstr | Timedelta | NoneGap threshold, as in :meth:detect_gaps (None: twice the median sampling interval).None
Returns
TypeDescription
DataFrameSingle-row DataFrame with columns: total_gaps, total_missing_seconds,
DataFramelongest_gap_seconds, shortest_gap_seconds, mean_gap_seconds,
DataFramedata_span_seconds, gap_fraction. data_span_seconds is the
DataFrametime from the first to the last sample, with or without gaps.
DataFrameWithout gaps total_missing_seconds, longest_gap_seconds
DataFrameand gap_fraction are 0 and shortest_gap_seconds /
DataFramemean_gap_seconds are NaN (there is no gap to measure).

coverage_by_period​

methodsource
coverage_by_period(
window: str = "1h", min_gap: str | pd.Timedelta | None = None
) -> pd.DataFrame

Data coverage percentage per time window.

For each window, reports how much of the window actually contains data: the time the data covers minus any internal gaps. The data covers first sample, last sample + one sampling step), the sampling step being the median positive interval between consecutive samples (the last sample holds for one step, as every other sample holds until the next one; a signal without a positive step covers no time after its last sample). Time of an edge window before the first sample or after that end counts as missing, so data 10:30:00-11:29:59 at 1 s reads 50 % in both hourly windows -- the same as SignalQualityEvents.data_completeness.

Parameters
NameTypeDescriptionDefault
window[strResample window (e.g. '1h', '1D', '15min').'1h'
min_gapstr | Timedelta | NoneGap threshold, as in :meth:detect_gaps: a step strictly longer than it is a gap. Defaults to 2x the median sampling interval (auto-detected).None
Returns
NameTypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, sample_count, coverage_pct, gap_count,
DataFramegap_seconds. end is the next period start.
DataFramegap_seconds includes the missing edge time of the first and
DataFramelast window; gap_count counts only the internal gaps (those
ofDataFramemeth:detect_gaps) overlapping the window.

interpolation_candidates​

methodsource
interpolation_candidates(
max_gap: str = "10s", min_gap: str = "0s"
) -> pd.DataFrame

Identify gaps small enough to safely interpolate.

Parameters
NameTypeDescriptionDefault
max_gapstrMaximum gap duration to consider for interpolation.'10s'
min_gapstrMinimum gap duration (ignore trivially small gaps). A zero-length step (duplicate timestamp) is never a gap.'0s'
Returns
TypeDescription
DataFrameDataFrame with columns: start, end, duration_seconds, uuid,
DataFramesource_uuid, gap_duration_seconds, value_before, value_after,
DataFramevalue_jump, safe_to_interpolate.
DataFramesafe_to_interpolate is True when the value jump across the
DataFramegap is within 2 standard deviations of the signal.