utils¶
- check_observations(observations, required_columns, allow_overlapping=False, allow_unsorted=False)¶
Checks that the observations are valid.
- Parameters:
observations (
DataFrame) – The observations to check.required_columns (
Iterable[str]) – The columns that are required in the observations.allow_overlapping (
bool, default:False) – Whether overlapping intervals are allowed.allow_unsorted (
bool, default:False) – Whether unsorted intervals are allowed.
- Return type:
- Returns:
The checked observations.
- Raises:
ValueError – If the observations are missing required columns.
ValueError – If the observations are not sorted by ‘start’.
ValueError – If the observations are overlapping.
- ensure_matching_index_columns(observations, reference_observations, index_columns)¶
Validates if two sets of observations have matching index columns.
- ensure_single_index(observations, *, index_columns, drop=True)¶
Ensure that the observations DataFrame has a single index key combination.
- infill_observations(observations, observation_stop=None, *, background_category='none')¶
Infill observations with intervals of the background category.
- Parameters:
- Return type:
- Returns:
The infilled observations.
- remove_overlapping_observations(observations, *, index_columns, priority_function, max_allowed_overlap, drop_overlapping=True, drop_overlapping_column=True)¶
Removes overlapping observations.
- Parameters:
observations (
DataFrame) – The set of observations.index_columns (
tuple[str,...]) – The columns to use as index.priority_function (
Callable[[DataFrame],Iterable[float]]) – A function that assigns a priority to each observation, lower values indicate higher priority.max_allowed_overlap (
float) – The maximum allowed overlap between observations.drop_overlapping (
bool, default:True) – Whether to drop overlapping observations.drop_overlapping_column (
bool, default:True) – Whether to drop the overlapping column.
- Return type:
- Returns:
Non-overlapping observations.
- to_observations(y, category_names, drop=None, timestamps=None)¶
Convert a 1D array of category labels to a DataFrame of observations.
- Parameters:
y (
ndarray) – A 1D array of category labels.drop (
Iterable[str] |None, default:None) – Categories that should be dropped from the resulting observations.timestamps (
ndarray|None, default:None) – Timestamps that correspond to the category labels. If not provided, timestamps are starting from 0.
- Return type:
- Returns:
Observations with columns “start”, “stop”, and “category”.
- to_y(observations, *, start=0, stop=None, dtype=<class 'str'>)¶
Convert observations to a 1D array of category labels.
- Parameters:
- Return type:
- Returns:
A 1D array of category labels.