Skip to main content
Version: Next

ts_shape.loader.timeseries.databricks_unity_energy_loader

Classes
NameDescription
DatabricksUnityEnergyLoaderLoad CSV energy timeseries and series metadata governed by Unity Catalog.

DatabricksUnityEnergyLoader​

classsource
DatabricksUnityEnergyLoader(
volume_path: str | None = None,
*,
catalog: str | None = None,
schema: str | None = None,
volume: str | None = None,
prefix: str = "",
base_path: str = "/Volumes",
thousands: str | None = None,
decimal: str = ".",
validate: bool = True
) -> None

Load CSV energy timeseries and series metadata governed by Unity Catalog.

Unity Catalog exposes the same CSV energy files that already live in your cloud storage (an external UC Volume over, e.g., an Azure blob container). The on-disk layout is unchanged::

<volume_root>/<prefix>/
.meta/
series.csv ← series metadata (tab-separated)
csv/
YYYY/MM/DD/
<series_id>.csv ← interval readings: time, value columns

All load methods return the standard ts-shape schema::

systime | uuid | value_double | is_delta

where uuid is the series_id (stem of the CSV filename), so the frames flow straight into every ts-shape transformation, event detector, Pipeline and DataIntegratorHybrid without any change.

Designed for use inside Databricks notebooks / pipelines. A UC Volume is FUSE-mounted at /Volumes/<catalog>/<schema>/<volume>/..., so this loader reads CSV directly from that mounted path with pandas.read_csv and keeps the resource footprint low:

  • No download step and no databricks-sdk / network client -- the mounted Volume is read like a local directory.
  • Navigates only the day folders in range (csv/YYYY/MM/DD) instead of scanning the whole tree, so a one-day query never lists the whole Volume.
  • Streaming generator (:meth:stream_by_time_range) yields one series at a time so the driver never has to hold the full dataset in memory.

Reads are sequential by design (no thread pool) to avoid adding CPU/memory pressure on a shared cluster driver.

Off-cluster (outside Databricks) the same code works against any mounted or synced copy of the Volume; if you cannot mount it, use :class:AzureBlobEnergyLoader against the underlying storage instead.

Functions
NameDescription
load_series_metadataRead .meta/series.csv and return as a DataFrame.
load_by_time_rangeLoad all CSV files in csv/YYYY/MM/DD/ for each date in [start, end].
load_by_series_idsLoad specific series by ID.
stream_by_time_rangeStream CSV files one at a time as (series_id, DataFrame) tuples.
list_seriesList all series IDs present in the Volume by scanning csv/.
fetch_data_as_dataframeReturn a combined DataFrame, for Pipeline / DataIntegratorHybrid.

Provide either an explicit volume_path or the catalog / schema / volume triple (joined under base_path)::

# explicit mounted path
DatabricksUnityEnergyLoader(
volume_path="/Volumes/main/plant/energy",
)

# from catalog/schema/volume parts
DatabricksUnityEnergyLoader(
catalog="main", schema="plant", volume="energy",
)
Parameters
NameTypeDescriptionDefault
volume_pathstr | NoneFull mounted Volume root, e.g. /Volumes/<catalog>/<schema>/<volume>.None
catalogstr | NoneUC catalog name (used when volume_path is omitted).None
schemastr | NoneUC schema name (used when volume_path is omitted).None
volumestr | NoneUC volume name (used when volume_path is omitted).None
prefixstrOptional sub-path beneath the Volume root holding the .meta/ and csv/ folders.''
base_pathstrMount root for Volumes; /Volumes inside Databricks.'/Volumes'
thousandsstr | NoneThousands separator for pd.read_csv (default None).None
decimalstrDecimal separator for pd.read_csv (default ".").'.'
validateboolWarn (LoaderConfigWarning) if the resolved root does not exist, so a missing/mistyped mount fails loudly but cheaply.True

load_series_metadata​

methodsource
load_series_metadata() -> pd.DataFrame

Read .meta/series.csv and return as a DataFrame.

id, label_lvl1, label_lvl2, label_lvl3, label_lvl4,

description, unit, hierarchy_lvl1 … hierarchy_lvl6

Returns an empty DataFrame with the expected columns, and emits a :class:~ts_shape.errors.LoaderConfigWarning, when the file does not exist.

Raises
TypeDescription
LoaderErrorWhen the file exists but cannot be read or parsed.

load_by_time_range​

methodsource
load_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
series_ids: list[str] | None = None,
*,
errors: ErrorsMode = "warn"
) -> pd.DataFrame

Load all CSV files in csv/YYYY/MM/DD/ for each date in [start, end].

Day folders are UTC days and are read in full; rows whose systime falls outside [start, end] are then dropped. A date-only end ("2026-01-13") keeps that whole day; naive bounds are UTC.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart date/datetime (inclusive).required
endstr | TimestampEnd date/datetime (inclusive).required
series_idslist[str] | NoneOptional list of series IDs to load. Loads all if None.None
errorsErrorsMode"warn" (default) skips a CSV that cannot be read or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped file; "raise" raises :class:~ts_shape.errors.LoaderError instead.'warn'
Returns
TypeDescription
DataFrameStandard schema DataFrame: systime

load_by_series_ids​

methodsource
load_by_series_ids(
series_ids: list[str],
start: str | pd.Timestamp | None = None,
end: str | pd.Timestamp | None = None,
*,
errors: ErrorsMode = "warn"
) -> pd.DataFrame

Load specific series by ID.

With start/end: visits only the day folders in range, keeps files whose stem matches a requested series_id and drops rows outside [start, end] (as :meth:load_by_time_range). Without dates: walks csv/ and filters by stem. With only one bound the range is open on the other side (day folders on or after start, or on or before end).

Parameters
NameTypeDescriptionDefault
series_idslist[str]Series IDs to load.required
startstr | Timestamp | NoneOptional start date filter (inclusive, whole days).None
endstr | Timestamp | NoneOptional end date filter (inclusive, whole days).None
errorsErrorsMode"warn" (default) skips a CSV that cannot be read or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped file; "raise" raises :class:~ts_shape.errors.LoaderError instead.'warn'
Returns
TypeDescription
DataFrameStandard schema DataFrame: systime

stream_by_time_range​

methodsource
stream_by_time_range(
start: str | pd.Timestamp,
end: str | pd.Timestamp,
series_ids: list[str] | None = None,
*,
errors: ErrorsMode = "warn"
) -> Iterator[tuple[str, pd.DataFrame]]

Stream CSV files one at a time as (series_id, DataFrame) tuples.

Memory-efficient alternative to :meth:load_by_time_range for large date ranges -- the recommended low-memory entry point in pipelines. Rows outside [start, end] are dropped the same way.

Parameters
NameTypeDescriptionDefault
startstr | TimestampStart date/datetime (inclusive).required
endstr | TimestampEnd date/datetime (inclusive).required
series_idslist[str] | NoneOptional series filter.None
errorsErrorsMode"warn" (default) skips a CSV that cannot be read or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped file; "raise" raises :class:~ts_shape.errors.LoaderError instead.'warn'
Yields
TypeDescription
tuple[str, DataFrame](series_id, DataFrame) where DataFrame has the standard schema.

list_series​

methodsource
list_series() -> list[str]

List all series IDs present in the Volume by scanning csv/.

Returns
TypeDescription
list[str]Sorted list of unique series ID strings.

fetch_data_as_dataframe​

methodsource
fetch_data_as_dataframe(
start: str | pd.Timestamp | None = None,
end: str | pd.Timestamp | None = None,
series_ids: list[str] | None = None,
*,
errors: ErrorsMode = "warn"
) -> pd.DataFrame

Return a combined DataFrame, for Pipeline / DataIntegratorHybrid.

With a start/end pair this delegates to :meth:load_by_time_range (visiting only the in-range day folders). With only one bound the range is open on the other side: every day folder on or after start (or on or before end) is read. With no bounds it loads every series under csv/.

Parameters
NameTypeDescriptionDefault
startstr | Timestamp | NoneStart date/datetime (inclusive, whole days); None leaves the start open.None
endstr | Timestamp | NoneEnd date/datetime (inclusive, whole days); None leaves the end open.None
series_idslist[str] | NoneSeries IDs to load. None loads every series.None
errorsErrorsMode"warn" (default) skips a CSV that cannot be read or parsed and emits one :class:~ts_shape.errors.DataQualityWarning naming every skipped file; "raise" raises :class:~ts_shape.errors.LoaderError instead.'warn'
Returns
TypeDescription
DataFrameStandard schema DataFrame: systime