segments_labeling

Segment labeling utilities for labeled time series providers.

class pysatl_cpd.data.providers.labeled.segments_labeling.SegmentsLabeling(segments)[source]

Bases: Sequence[SegmentInfo]

Labeled segments with query and transformation capabilities.

This class provides a sequence of segment information objects with methods for querying segments and bisegments, cutting slices, merging labelings, and converting to/from DataFrames.

Parameters:

segments (Iterable[SegmentInfo]) – Iterable of segment information objects.

__init__(segments)[source]
Parameters:

segments (Iterable[SegmentInfo])

Return type:

None

query_segments(filter_fn=None)[source]

Query segments by optional filter.

Parameters:

filter_fn (Callable[[SegmentInfo], bool] | None) – Optional predicate function for segment filtering.

Returns:

Filtered sequence of segment information.

Return type:

Sequence[SegmentInfo]

query_bisegments(filter_fn=None)[source]

Query bisegments by optional filter.

Parameters:

filter_fn (Callable[[BisegmentInfo], bool] | None) – Optional predicate function for bisegment filtering.

Returns:

Filtered sequence of bisegment information.

Return type:

Sequence[BisegmentInfo]

property states: set[StateDescriptor]

Return the set of states represented by the labeling.

Returns:

Set of unique state descriptors in this labeling.

Return type:

states

property transitions: set[TransitionDescriptor]

Return transitions between consecutive segments.

Returns:

Set of unique transition descriptors between consecutive segments.

Return type:

transitions

cut(start, stop)[source]

Cut a slice from the labeling.

Parameters:
  • start (int) – Start index of the slice.

  • stop (int) – End index of the slice.

Returns:

New labeling containing the cut portion.

Return type:

SegmentsLabeling

Raises:

ValueError – If start is negative, stop is less than start, or stop exceeds the data length.

classmethod merge(labelings)[source]

Merge multiple labelings into one.

Parameters:

labelings (Sequence[SegmentsLabeling]) – Sequence of labelings to merge.

Returns:

Single merged labeling with adjusted offsets.

Return type:

SegmentsLabeling

__getitem__(index)[source]
Overloads:
  • self, index (int) → SegmentInfo

  • self, index (slice) → Self

Parameters:

index (int | slice)

Return type:

SegmentInfo | Self

Return one segment or a sliced labeling.

Parameters:

index (int | slice) – Integer index or slice.

Returns:

Segment information or a new labeling slice.

Return type:

item

__len__()[source]

Return the number of segments.

Returns:

Number of labeled segments.

Return type:

int

property data_len: int

Return the total covered data length.

Returns:

Total data length across all segments.

Return type:

length

classmethod from_dataframe(frame, segment_num_col='segment', segment_start_col='start', segment_end_col='end')[source]

Create labeling from a DataFrame.

Parameters:
  • frame (DataFrame) – Input DataFrame containing segment data.

  • segment_num_col (str | None) – Name of the column containing segment numbers.

  • segment_start_col (str) – Name of the column containing segment start indices.

  • segment_end_col (str) – Name of the column containing segment end indices.

Returns:

New labeling instance constructed from the DataFrame.

Return type:

Self

to_dataframe(segment_num_col='segment', segment_start_col='start', segment_end_col='end')[source]

Convert labeling to a DataFrame.

Parameters:
  • segment_num_col (str | None) – Name of the column for segment numbers.

  • segment_start_col (str) – Name of the column for segment start indices.

  • segment_end_col (str) – Name of the column for segment end indices.

Returns:

DataFrame representation of the labeling.

Return type:

DataFrame