A (very preliminary) library for building versioned time series as they appeared at any point in time.
Project description
ts-asof
The goal of this library is to help reconstruct versioned as_of time series snapshots. A necessary step for backtesting in nowcast environments. To be specific, given a finalized dataset, and access to revisions, this library reconstructs an as_of series for any time in the query window to allow users to obtain a snapshot of the series that was as of the desired date.
Notably, this setup assumes that:
- You have access to a ‘finalized’ ground truth dataset, which reflects revisions over all time periods before the end date.
- You have access to ‘snapshots’ or ‘issues’ which are incomplete, but provide revisions of past data that were known as of the date of issue.
For example, in the fluview endpoint in the epidata api, there is an issue parameter that yeilds all revisions as of the issue date. So if I am interested in knowing what was known about 2019-01 influenza-like-illness statstics as of 2020-01, we can track all the issues between the initial release on 2019-01 until 2020-01. Ths doesn't prevent further updates or revisions of the 2019-01 records to be updated after 2020-01 of course, but it provides an accurate snapshot of 2019-01 statistics as of 2020-01.
Install
With uv:
uv add asof
and with pip,
pip install asof
A note on dependencies. The current iteration requires epidata as it was designed with the sole purpose of creating an asof version of the fluview endpoint. Future iterations can remove this dependencies or modify to opt into it.
Usage
Please see the */examples/wili_example.ipynb * for a demo and extra notes on usage.
Algorithm
Step 1: Build Phase
- Fetch finalized snapshot once: Query all data with complete revision history
[start, end] - Identify stable base: Find all time points finalized before an initial version threshold (these never change again)
- Build delta chain: For each subsequent version v:
- Fetch only the active revision window — time points where
max_version > v - Skip time points already finalized (key optimization!)
- Store sparse delta containing only revised values
- Fetch only the active revision window — time points where
Step 2: Reconstruction To reconstruct the series as of version V:
- Load delta file for version V
- Extract its start time point tstart from metadata
- Step back one time point: tprev = tstart - 1
- Look up which version last modified tprev in the pre-computed
max_version_lookup - Jump to that version's delta file and repeat
- Terminate when reaching the frozen base
- Concatenate:
base ⊕ delta_chain
Future Improvements
- Added flexibility. The main pain point in the current iteration is the lack of a unified
datetimehandling of the date indices. This is very fragile and would be the key item to address for future iterations. - Allowing for a
stepparameter for reconstruction. This saves time and space if the user does not needasofreconstruction for every time step betweenstart_date + init_window_sizeandend_date, but rather, everystep. - Support for other data streams. As of now, only
epidatasupport for thefluviewendpoint is available. This framework can easily be extended to otherepidataAPI endpoints that don't haveasofavailable. However, support for other streams (e.g., FRED) would require the user to build a customDataSourceabstract base class that mimics the implementation inepidata.pyforDelphiEpidata.
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 ts_asof-0.1.1.tar.gz.
File metadata
- Download URL: ts_asof-0.1.1.tar.gz
- Upload date:
- Size: 155.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c2e6c82a9aea82fe6be44d5fc1f9419eff83cd5a4d252de59a5477742da5cc8
|
|
| MD5 |
dc4d1ec9cf998fd62428f98deca3e203
|
|
| BLAKE2b-256 |
bc6449d743b1a06c5f818946b65df6cf1911d5bc567c40d6f038f3c8d0d630e0
|
File details
Details for the file ts_asof-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ts_asof-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ded407e53a681e1f3abd777b8fa12df792e6c33009763a6a3eae394c766017f4
|
|
| MD5 |
4d99034b31f795987ce0e92f38b16ccd
|
|
| BLAKE2b-256 |
721a597bf152213f7445a119d70ad2e5b47a7400c366d057e131c3c70f499b77
|