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
| Name | Description |
|---|
most_populated_value_column | The value_* column with the most values in group, or None. |
parse_times | A time column as datetime64; unparseable values become NaT. |
signal_groups | Rows per signal, keyed by the uuid as text, sorted by key. |
infer_spec | Infer the spec of one signal from its rows. |
infer_specs | Infer a :class:SignalSpec for every uuid in a long-format frame. |
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(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
| Name | Type | Description | Default |
|---|
values | Series | The time column. | required |
Returns
| Type | Description |
|---|
Series | The parsed column. |
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
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Long-format frame. | required |
uuid_column | str | Signal identifier column. | required |
time_column | str | Timestamp column. | required |
Returns
| Type | Description |
|---|
list[tuple[str, DataFrame]] | (uuid, rows) pairs. |
Raises
infer_spec(
group: pd.DataFrame, uuid: str, time_column: str = "systime"
) -> SignalSpec
Infer the spec of one signal from its rows.
Parameters
| Name | Type | Description | Default |
|---|
group | DataFrame | The rows of one signal. | required |
uuid | str | The signal's uuid, written to the spec. | required |
time_column | str | Timestamp column. | 'systime' |
Returns
| Type | Description |
|---|
SignalSpec | The inferred :class:SignalSpec; notes explain each field. |
Raises
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
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Long-format data (systime, uuid, value_*). | required |
overrides | Mapping[str, Mapping[str, Any]] | None | {uuid: {field: value}} applied after inference -- the place for what the data cannot tell (units, outage limits). | None |
uuid_column | str | Column identifying the signal. | 'uuid' |
time_column | str | Timestamp column. | 'systime' |
Returns
| Type | Description |
|---|
SignalSpecs | class:SignalSpecs keyed by uuid (as text); each spec's notes |
SignalSpecs | explain the inferred fields. |
Raises