API Reference
TimeSeries
- class timedatamodel.TimeSeries(df=None, *, name, description=None, unit='dimensionless', timezone='UTC', frequency=None, data_type=None, timeseries_type=TimeSeriesType.FLAT)[source]
Bases:
_TimeSeriesReprMixinPolars-backed container for time series data with rich metadata.
The underlying
dfis optional. Construct withdf=Noneto declare a series structure (name, unit, data type, …) before any data exists — useful for registering series in a catalog. Methods that need data (converters,head/tail,convert_unit, …) raiseValueErrorwhen no df is attached. Usehas_dfto check.- Parameters:
df (
DataFrame|None) – Apolars.DataFramewhose columns conform to one of the recognisedDataShapepatterns, orNonefor a metadata-only instance. All timestamp columns must usepl.Datetime("us", time_zone="UTC").name (
str) – Series name (e.g."wind_power","electricity.supply").unit (
str) – Canonical physical unit string (e.g."MW","dimensionless").timezone (
str) – IANA timezone string for display purposes. Internal data is always UTC; this is a metadata hint only.frequency (
Frequency|None) – Pandas offset alias describing the expected data cadence.data_type (
DataType|None) – Semantic nature of the observations (DataType).timeseries_type (
TimeSeriesType) – Storage/versioning model (TimeSeriesType).
- property shape: DataShape | None
Which temporal columns are present (inferred from the DataFrame).
Nonefor metadata-only instances.
- property columns: list[str]
Column names present in the underlying Polars DataFrame.
Empty list for metadata-only instances.
- property df: DataFrame | None
The underlying
polars.DataFrame(read-only by convention).Nonefor metadata-only instances.
- property has_missing: bool
True if the
valuecolumn contains any null values.Falsefor metadata-only instances.
- classmethod from_polars(df, *, name, description=None, unit='dimensionless', timezone='UTC', frequency=None, data_type=None, timeseries_type=TimeSeriesType.FLAT)[source]
Create a
TimeSeriesdirectly from apolars.DataFrame.All timestamp columns must already use
pl.Datetime("us", time_zone="UTC").- Return type:
- Parameters:
- classmethod from_list(data, *, name, description=None, unit='dimensionless', timezone='UTC', frequency=None, data_type=None, timeseries_type=TimeSeriesType.FLAT)[source]
Create a
TimeSeriesfrom a column-oriented dict of lists.Accepts the format returned by
to_list(). Timestamp columns are normalised to UTC automatically.
- classmethod from_numpy(data, *, name, description=None, unit='dimensionless', timezone='UTC', frequency=None, data_type=None, timeseries_type=TimeSeriesType.FLAT)[source]
Create a
TimeSeriesfrom a column-oriented dict of NumPy arrays.Accepts the format returned by
to_numpy(). Timestamp columns (numpy.datetime64, always timezone-naive) are localised to UTC.Requires
numpy.
- classmethod from_pyarrow(table, *, name, description=None, unit='dimensionless', timezone='UTC', frequency=None, data_type=None, timeseries_type=TimeSeriesType.FLAT)[source]
Create a
TimeSeriesfrom a PyArrow Table.Accepts the format returned by
to_pyarrow(). Arrowtimestamp[us, UTC]columns are converted automatically.Requires
pyarrow.
- classmethod from_pandas(df, *, name, description=None, unit='dimensionless', timezone='UTC', frequency=None, data_type=None, timeseries_type=TimeSeriesType.FLAT)[source]
Create a
TimeSeriesfrom apandas.DataFrame.Only
SIMPLEandVERSIONEDshapes can be constructed viafrom_pandas.AUDITandCORRECTEDshapes (which require achange_timecolumn) are read-only results from the database layer.The data shape is inferred from the column names (and MultiIndex levels if the DataFrame uses an index).
- Raises:
ValueError – If the DataFrame contains a
change_timecolumn.- Return type:
- Parameters:
- validate_for_insert()[source]
Validate that this TimeSeries can be inserted and return the underlying DataFrame with its shape.
Only
DataShape.SIMPLEandDataShape.VERSIONEDare supported for insert.- Return type:
- Raises:
ValueError – If
shapeisDataShape.AUDITorDataShape.CORRECTED.
- to_pandas()[source]
Convert to a
pandas.DataFrame.Restores the conventional index:
SIMPLE—valid_timeas index.VERSIONED—(knowledge_time, valid_time)MultiIndex.AUDIT—(knowledge_time, change_time, valid_time)MultiIndex.CORRECTED—(valid_time, change_time)MultiIndex.
- Return type:
- to_list()[source]
Return the series as a column-oriented dict of lists.
Each key is a column name; each value is a Python list of that column’s values. Timestamps are Python
datetimeobjects; null values areNone.Example:
{"valid_time": [datetime(...), ...], "value": [1.0, None, 3.0, ...]}
- Return type:
- to_numpy()[source]
Return the series as a dictionary of NumPy arrays.
Each column maps to a 1-D
numpy.ndarray. Timestamp columns becomenumpy.datetime64[us]values; null values becomeNaNorNaT.Requires
numpy. Install with:pip install numpy.- Return type:
dict[str, np.ndarray]
- to_pyarrow()[source]
Return the series as a
pyarrow.Table.All timestamp columns are Arrow
timestamp[us, UTC].Requires
pyarrow. Install with:pip install pyarrow.- Return type:
pa.Table
- coverage_bar()[source]
Return a
CoverageBarshowing value coverage.True= value present,False= null/missing. In Jupyter the coverage bar renders as an SVG.- Return type:
CoverageBar
- head(n=5)[source]
Return the first n rows as a new
TimeSeries.- Return type:
- Parameters:
n (int)
- tail(n=5)[source]
Return the last n rows as a new
TimeSeries.- Return type:
- Parameters:
n (int)
- convert_unit(target_unit)[source]
Return a new
TimeSerieswith values converted to target_unit.Uses the pint library for unit conversion. The
unitmetadata field is updated to target_unit.- Parameters:
target_unit (
str) – Target unit string understood by pint (e.g."km/h","kW").- Raises:
ImportError – If pint is not installed.
pint.DimensionalityError – If the current unit and target_unit are dimensionally incompatible.
- Return type:
DataShape
Frequency
DataType
- class timedatamodel.DataType(*values)[source]
- ACTUAL = 'ACTUAL'
- OBSERVATION = 'OBSERVATION'
- DERIVED = 'DERIVED'
- CALCULATED = 'CALCULATED'
- ESTIMATION = 'ESTIMATION'
- FORECAST = 'FORECAST'
- PREDICTION = 'PREDICTION'
- SCENARIO = 'SCENARIO'
- SIMULATION = 'SIMULATION'
- RECONSTRUCTION = 'RECONSTRUCTION'
- REFERENCE = 'REFERENCE'
- BASELINE = 'BASELINE'
- BENCHMARK = 'BENCHMARK'
- IDEAL = 'IDEAL'
TimeSeriesType
DataPoint
GeoLocation
- class timedatamodel.GeoLocation(latitude, longitude)[source]
-
- distance_to(other, unit='km')[source]
Haversine great-circle distance to other.
- Return type:
- Parameters:
other (GeoLocation)
unit (str)
- bearing_to(other)[source]
Initial bearing in degrees [0, 360) from self to other.
- Return type:
- Parameters:
other (GeoLocation)
- midpoint(other)[source]
Geographic midpoint on the great circle.
- Return type:
- Parameters:
other (GeoLocation)
GeoArea
- class timedatamodel.GeoArea(polygon, name=None)[source]
- Parameters:
polygon (Polygon)
name (str | None)
- polygon: Polygon
- property centroid: GeoLocation
- classmethod from_coordinates(coords, name=None)[source]
Create a GeoArea from a list of (lat, lon) coordinate pairs.
- contains_point(location)[source]
True if location is inside this area.
- Return type:
- Parameters:
location (GeoLocation)
- distance_to(other)[source]
Approximate distance in km (centroid-based Haversine).
Returns 0.0 if the point is contained or the areas overlap.
- Return type:
- Parameters:
other (GeoLocation | GeoArea)