Files and backends¶
File I/O¶
Read and write SignalFrames as Parquet and CSV.
Parquet is the lossless format. Each stream is a float64 column next to a
<stream>__flags uint16 column. Units, metadata and provenance go in the
Arrow schema metadata under the flexsignal key. A Parquet file written by
any other tool also reads, as long as it has a datetime index or column.
CSV is for interchange. Timestamps are written in ISO 8601 with their UTC offset. Floats round-trip exactly: pandas writes their shortest repr and, from pandas 3, parses at full precision by default.
- flexsignal.io.read_parquet(path: str | Path, *, units: Mapping[str, str] | None = None, timezone: str | None = None, time_column: str | None = None) SignalFrame¶
Read a SignalFrame from Parquet.
- Parameters:
path – The file.
units – Units per stream. These override units stored in the file.
timezone – Time zone for a timezone-naive time index (files from other tools). If not given, naive timestamps are taken as this machine’s local time, with a warning.
time_column – Column holding the timestamps, if they aren’t the index.
- Returns:
The SignalFrame.
- Raises:
SignalDataError – If the file has no usable time index.
- flexsignal.io.write_parquet(sf: SignalFrame, path: str | Path) Path¶
Write a SignalFrame to Parquet, keeping flags, metadata and provenance.
- Parameters:
sf – The frame to write.
path – Output path. Parent directories are created.
- Returns:
The path written.
- flexsignal.io.read_csv(path: str | Path, *, time_column: str = 'timestamp', timezone: str | None = None, units: Mapping[str, str] | None = None) SignalFrame¶
Read a SignalFrame from CSV.
Columns named
<stream>__flagsare read back as that stream’s flags.- Parameters:
path – The file. A UTF-8 byte-order mark is accepted.
time_column – Column holding the timestamps.
timezone – Time zone of timestamps written without an offset. If not given, they are taken as this machine’s local time, with a warning.
units – Units per stream.
- Returns:
The SignalFrame.
- Raises:
SignalDataError – If the file or the time column is missing, or naive timestamps fall in a daylight-saving change.
- flexsignal.io.write_csv(sf: SignalFrame, path: str | Path, *, include_flags: bool = False) Path¶
Write a SignalFrame’s values (and optionally flags) to CSV.
- Parameters:
sf – The frame to write.
path – Output path. Parent directories are created.
include_flags – Also write one
<stream>__flagscolumn per stream.
- Returns:
The path written.
Backends¶
The backend registry: string keys that name an object in an existing library.
A step names the algorithm it uses by a key such as "scipy:PchipInterpolator"
or "sklearn:HuberRegressor". The target is imported only when the key is
used, so an optional library costs nothing until a step needs it. If the library
is missing, the error says which extra installs it.
Besides registered keys, any "package.module:attribute" string resolves
directly, which is how user code plugs in. Third-party packages register keys
through the flexsignal.backends entry-point group. Each entry point names a
callable that is called with no arguments and registers its keys.
key |
resolves to |
extra |
description |
|---|---|---|---|
|
core |
Piecewise-linear interpolation. |
|
|
core |
Akima piecewise-cubic interpolation; robust to outliers in shape. |
|
|
core |
Shape-preserving piecewise-cubic (PCHIP) interpolation; no overshoot. |
|
|
core |
Nearest-neighbour and previous-value interpolation. |
- flexsignal.backends.get_backend(key: str) Any¶
Return the object a backend key names, importing it on first use.
- Parameters:
key – A registered key, or any
"package.module:attribute"string.- Returns:
The imported object (a class, function or module attribute).
- Raises:
SignalBackendError – If the key is unknown, or its library is not installed.
- flexsignal.backends.register_backend(key: str, target: str, *, extra: str | None = None, description: str = '', docs_url: str | None = None) BackendInfo¶
Register a backend key.
- Parameters:
key – The key steps use, as
"library:Name".target – What it resolves to, as
"package.module:attribute".extra – The flex-signal extra that installs the library, if it is optional.
description – One line on what it is.
docs_url – Link to the upstream documentation.
- Returns:
The registered
BackendInfo.- Raises:
SignalBackendError – If
keyis already registered with another target.
- flexsignal.backends.registered_backends() list[BackendInfo]¶
Return every registered backend, sorted by key.
- class flexsignal.backends.BackendInfo¶
A registered backend key.