Skip to main content
Version: Next

ts_shape.signals.infer

Infer :class:~ts_shape.signals.spec.SignalSpec from data.

Inference is a starting point, not an oracle: every inferred field records why it was chosen in spec.notes, and anything the data cannot tell (units, a counter that never reset yet, the real outage threshold of a change-encoded signal) should be set with :meth:SignalSpecs.override.

Functions
NameDescription
most_populated_value_columnThe value_* column with the most values in group, or None.
parse_timesA time column as datetime64; unparseable values become NaT.
signal_groupsRows per signal, keyed by the uuid as text, sorted by key.
infer_specInfer the spec of one signal from its rows.
infer_specsInfer a :class:SignalSpec for every uuid in a long-format frame.

most_populated_value_column​

functionsource
most_populated_value_column(group: pd.DataFrame) -> str | None

The value_* column with the most values in group, or None.

Ties go to the first of value_double, value_integer, value_bool, value_string; None when no value column has a value. Also used by the detectors' value-column check (:func:ts_shape.utils.signal_checks.warn_if_values_elsewhere).

parse_times​

functionsource
parse_times(values: pd.Series) -> pd.Series

A time column as datetime64; unparseable values become NaT.

Text with different UTC offsets (+01:00 next to +02:00) is converted to UTC with a :class:~ts_shape.errors.DataQualityWarning.

Parameters
NameTypeDescriptionDefault
valuesSeriesThe time column.required
Returns
TypeDescription
SeriesThe parsed column.

signal_groups​

functionsource
signal_groups(
dataframe: pd.DataFrame, uuid_column: str, time_column: str
) -> list[tuple[str, pd.DataFrame]]

Rows per signal, keyed by the uuid as text, sorted by key.

Nullable, pyarrow and string columns are converted to NumPy dtypes first (the input is not changed). Rows without a uuid are dropped and uuids that differ only in type (1 and "1") are one signal; both cases emit a :class:~ts_shape.errors.DataQualityWarning.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format frame.required
uuid_columnstrSignal identifier column.required
time_columnstrTimestamp column.required
Returns
TypeDescription
list[tuple[str, DataFrame]](uuid, rows) pairs.
Raises
TypeDescription
ColumnNotFoundErrorWhen uuid_column or time_column is missing.

infer_spec​

functionsource
infer_spec(
group: pd.DataFrame, uuid: str, time_column: str = "systime"
) -> SignalSpec

Infer the spec of one signal from its rows.

Parameters
NameTypeDescriptionDefault
groupDataFrameThe rows of one signal.required
uuidstrThe signal's uuid, written to the spec.required
time_columnstrTimestamp column.'systime'
Returns
TypeDescription
SignalSpecThe inferred :class:SignalSpec; notes explain each field.
Raises
TypeDescription
ColumnNotFoundErrorWhen time_column is missing.

infer_specs​

functionsource
infer_specs(
dataframe: pd.DataFrame,
overrides: Mapping[str, Mapping[str, Any]] | None = None,
*,
uuid_column: str = "uuid",
time_column: str = "systime"
) -> SignalSpecs

Infer a :class:SignalSpec for every uuid in a long-format frame.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format data (systime, uuid, value_*).required
overridesMapping[str, Mapping[str, Any]] | None{uuid: {field: value}} applied after inference -- the place for what the data cannot tell (units, outage limits).None
uuid_columnstrColumn identifying the signal.'uuid'
time_columnstrTimestamp column.'systime'
Returns
TypeDescription
SignalSpecsclass:SignalSpecs keyed by uuid (as text); each spec's notes
SignalSpecsexplain the inferred fields.
Raises
TypeDescription
ColumnNotFoundErrorWhen uuid_column or time_column is missing.