Skip to main content
Version: 0.0.98

ts_shape.loader.metadata.workbook

Read a plant's datapoint workbook (.xlsx) without extra dependencies.

A datapoint export is often delivered as a workbook: one row per datapoint with uuid, label and the flattened configuration as config.<key> columns (config.nodePath[string], config.unit, ...), next to plain columns such as is_enabled, is_archived, scaling_factor and scaling_offset. It is the flat form of the JSON that :class:~ts_shape.loader.metadata.metadata_json_loader.MetadataJsonLoader reads.

  • :func:read_workbook reads one sheet as a frame (header in the first row) with the Python standard library only (zipfile + XML), so no Excel package is needed;
  • :func:nested_records turns such a flat frame into the records with a nested config dict the JSON loader takes.
Functions
NameDescription
read_workbookOne sheet of an .xlsx as a frame (header in row 1).
nested_recordsRecords with a nested config from a flat datapoint table.

read_workbook​

functionsource
read_workbook(path: str | Path, sheet: int | str = 0) -> pd.DataFrame

One sheet of an .xlsx as a frame (header in row 1).

Parameters
NameTypeDescriptionDefault
pathstr | PathThe workbook file.required
sheetint | strSheet position (0 = first) or name.0
Returns
TypeDescription
DataFrameOne row per non-empty sheet row; text, numbers (integral numbers as
DataFrameint) and booleans as stored. Empty cells are missing.
Raises
TypeDescription
FileNotFoundErrorWhen path does not exist.
ValueErrorWhen the file is not a workbook or has no such sheet.

nested_records​

functionsource
nested_records(frame: pd.DataFrame) -> list[dict[str, Any]]

Records with a nested config from a flat datapoint table.

config.<key> and config.<key>[type] columns become keys of the record's config dict (the [type] suffix of an export is dropped); every other column stays at the top level. Missing values are left out.