A lightweight data model for time series data with pandas, numpy, and polars support
Project description
TimeDataModel
A lightweight Python data model for time series data with native bridges to numpy, pandas, polars, and xarray.
TimeDataModel provides a structured, metadata-rich representation of time series data that lets you:
- 📐 Structure - Represent univariate, multivariate, N-dimensional, and hierarchical time series as typed Python objects;
- 🔄 Convert - Seamlessly convert between pandas DataFrames, numpy arrays, and polars DataFrames;
- 🗺️ Locate - Attach geographic coordinates and areas to time series with spatial filtering;
- 📏 Measure - Track and convert physical units with automatic dimensional validation;
- 📊 Validate - Inspect data quality with coverage bars, gap detection, and consistency checks;
- 💾 Serialize - Read and write time series to JSON and CSV with full metadata preservation.
⬇️ Installation | 📖 Documentation | 🚀 Examples
🧱 Core Data Classes
TimeDataModel represents time series data at multiple levels of complexity. The table below gives a summary of the available data classes.
| Class | Description |
|---|---|
📈 TimeSeries |
Univariate time series with scalar metadata (name, unit, frequency, timezone) |
📊 TimeSeriesTable |
Multivariate time series — multiple columns sharing the same timestamp index |
🧊 TimeSeriesArray |
N-dimensional time series with named dimensions and label-based selection |
📦 TimeSeriesCollection |
Heterogeneous container for series with different indices |
🌳 HierarchicalTimeSeries |
Tree-structured time series with aggregation across hierarchy levels |
🗺️ GeoLocation / GeoArea |
Geographic point and polygon types with distance, bearing, and containment |
⏱️ Frequency |
ISO 8601 duration-based frequencies (PT1H, P1D, P1M, etc.) |
🏷️ DataType |
Hierarchical taxonomy: ACTUAL → OBSERVATION, DERIVED; CALCULATED → ESTIMATION, REFERENCE, etc. |
🔌 Integrations
Each class provides to_X, from_X, and apply_X bridges to popular array and dataframe libraries.
| numpy | pandas | polars | xarray | |
|---|---|---|---|---|
| TimeSeries | ||||
to_X |
✅ | ✅ | ✅ | ✅ |
from_X |
— | ✅ | ✅ | ✅ |
apply_X |
✅ | ✅ | ✅ | ✅ |
| TimeSeriesTable | ||||
to_X |
✅ | ✅ | ✅ | ✅ |
from_X |
— | ✅ | — | ✅ |
apply_X |
✅ | ✅ | ✅ | ✅ |
| TimeSeriesArray | ||||
to_X |
✅ | ✅ | — | ✅ |
from_X |
✅ | — | — | ✅ |
apply_X |
— | ✅¹ | ✅¹ | ✅ |
¹ Gated: raises ValueError if the array has more than 2 non-time dimensions.
🚀 Quick Start
from datetime import datetime, timezone
from timedatamodel import TimeSeries, Frequency
# Create a univariate time series
ts = TimeSeries(
Frequency.PT1H,
timezone="UTC",
timestamps=[datetime(2024, 1, 1, i, tzinfo=timezone.utc) for i in range(24)],
values=[100.0 + i * 2.5 for i in range(24)],
name="power_output",
unit="MW",
)
# Convert to pandas DataFrame
df = ts.to_pandas_dataframe()
# Convert to numpy array
arr = ts.to_numpy()
# Arithmetic operations
ts_doubled = ts * 2
ts_shifted = ts + 50
# Inspect data quality
print(ts.coverage_bar())
# Serialize to JSON
json_str = ts.to_json()
✨ Key Features
- 📐 Multi-dimensional - From single series (
TimeSeries) to N-dimensional arrays (TimeSeriesArray) with.sel()and.isel()for label- and index-based selection; - 🔢 Arithmetic - Element-wise
+,-,*,/, comparisons, andabs()with automatic NaN handling; - 🗺️ Geospatial - Attach locations, compute distances (Haversine), filter by radius or area, and find nearest neighbors;
- 🌳 Hierarchical - Build tree structures with automatic aggregation (
SUM,MEAN,MIN,MAX) and cross-level unit conversion; - 📏 Units - Optional pint integration for physical unit tracking and conversion;
- 📊 Data Quality - Coverage bars (terminal + HTML), missing-value detection, and timestamp validation;
- 💾 Serialization - JSON and CSV I/O with full round-trip metadata preservation;
- 🐍 Type-safe - Full type hints with PEP 561 support.
⬇️ Installation
Install the stable release:
pip install timedatamodel
Install with optional dependencies:
pip install timedatamodel[pandas] # pandas support
pip install timedatamodel[polars] # polars support
pip install timedatamodel[geo] # geospatial support (shapely)
pip install timedatamodel[pint] # unit handling (pint)
pip install timedatamodel[all] # everything
Install in editable mode for development:
git clone https://github.com/rebase-energy/TimeDataModel.git
cd TimeDataModel
pip install -e .[dev]
📓 Examples
Explore the library through the example notebooks:
| # | Notebook | Topic |
|---|---|---|
| 01 | Getting Started | Creating and inspecting time series |
| 02 | NumPy & Pandas | Converting to and from numpy and pandas |
| 03 | Unit Handling | Physical unit conversion with pint |
| 04 | Operations | Arithmetic, slicing, and indexing |
| 05 | Multivariate | Working with multi-column time series |
| 06 | Arrays & Collections | N-dimensional data and heterogeneous containers |
| 07 | Data Quality | Coverage bars and validation |
| 08 | I/O | JSON and CSV serialization |
| 09 | Geospatial | Locations, areas, and spatial filtering |
| 10 | Hierarchical | Tree structures and aggregation |
🤝 Contributing
Contributions are welcome! Here are some ways to contribute to TimeDataModel:
- Propose new data classes or extend existing ones;
- Improve documentation or add example notebooks;
- Report bugs or suggest features via GitHub Issues.
📄 Licence
This project uses the MIT Licence.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file timedatamodel-0.1.4.tar.gz.
File metadata
- Download URL: timedatamodel-0.1.4.tar.gz
- Upload date:
- Size: 11.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ae64a902fe177934ac237b2920dbcdae062b7609114050214abb16d1b1af48
|
|
| MD5 |
31947a75e324ee2b652bbc374747f15c
|
|
| BLAKE2b-256 |
8ba1b86ac613b9c791b3ff3d63fa42de918cbc3488ddba9ad06313649ae8b64f
|
Provenance
The following attestation bundles were made for timedatamodel-0.1.4.tar.gz:
Publisher:
publish.yml on rebase-energy/TimeDataModel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timedatamodel-0.1.4.tar.gz -
Subject digest:
47ae64a902fe177934ac237b2920dbcdae062b7609114050214abb16d1b1af48 - Sigstore transparency entry: 1114511459
- Sigstore integration time:
-
Permalink:
rebase-energy/TimeDataModel@7a2ef7f3dcc458a082742deead16fecb5fd94b16 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/rebase-energy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a2ef7f3dcc458a082742deead16fecb5fd94b16 -
Trigger Event:
release
-
Statement type:
File details
Details for the file timedatamodel-0.1.4-py3-none-any.whl.
File metadata
- Download URL: timedatamodel-0.1.4-py3-none-any.whl
- Upload date:
- Size: 73.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11a8896ca35e241884e7ca5abce173ed7e1b86aa569695653b1b2a9f18eb1738
|
|
| MD5 |
60b120469826e663c50a67318c5cd3f7
|
|
| BLAKE2b-256 |
f975f077be94abdc313237612af4c39d710c42cfdb01a6068cf3a4ee8c7122cc
|
Provenance
The following attestation bundles were made for timedatamodel-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on rebase-energy/TimeDataModel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
timedatamodel-0.1.4-py3-none-any.whl -
Subject digest:
11a8896ca35e241884e7ca5abce173ed7e1b86aa569695653b1b2a9f18eb1738 - Sigstore transparency entry: 1114511469
- Sigstore integration time:
-
Permalink:
rebase-energy/TimeDataModel@7a2ef7f3dcc458a082742deead16fecb5fd94b16 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/rebase-energy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7a2ef7f3dcc458a082742deead16fecb5fd94b16 -
Trigger Event:
release
-
Statement type: