Skip to content

infer

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.

parse_times ¤

parse_times(values: 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 ¤

signal_groups(
    dataframe: 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:

Type Description
ColumnNotFoundError

When uuid_column or time_column is missing.

infer_spec ¤

infer_spec(
    group: 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:

Type Description
ColumnNotFoundError

When time_column is missing.

infer_specs ¤

infer_specs(
    dataframe: 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:

Type Description
ColumnNotFoundError

When uuid_column or time_column is missing.