Skip to main content

Temporal Aggregation & Disaggregation for Modern Python (Polars-first)

Project description

aggdisagg

Temporal Aggregation & Disaggregation for Modern Python

Python Polars License: MIT uv PyPI GitHub

aggdisagg social preview

Install & try in 10 seconds:

pip install aggdisagg
import polars as pl
from aggdisagg import TemporalAligner
df = pl.DataFrame({"date": ["2020", "2021"], "y": [100.0, 120.0]})
print(TemporalAligner().fit_transform(df, datetime_col="date", target_col="y"))

aggdisagg is a clean, Polars-first Python library for converting time series between frequencies with perfect aggregation consistency.

  • Disaggregate low → high frequency (with indicators)
  • Aggregate high → low frequency (symmetric)
  • Works with Polars (primary), pandas, and xarray

Installation + Try in 10 Seconds

pip install "aggdisagg[all]" && python -c "
import polars as pl
from datetime import date
from aggdisagg import TemporalAligner
df = pl.DataFrame({'date':[date(2020,1,1),date(2021,1,1)], 'y':[1000.,1200.]})
print(TemporalAligner(method='uniform').fit_transform(df, datetime_col='date', target_col='y'))
"

Quickstart with TemporalAligner

import polars as pl
from datetime import date
from aggdisagg import TemporalAligner

df = pl.DataFrame({
    "date": [date(2020, 1, 1), date(2021, 1, 1), date(2022, 1, 1)],
    "y": [1200.0, 1500.0, 1350.0],      # low-frequency target
    "indicator": [100.0, 125.0, 110.0], # high-frequency indicator
})

aligner = TemporalAligner(
    method="chow-lin-opt",
    target_freq="1mo",
    agg="sum",
    indicator_cols=["indicator"],
)

monthly = aligner.fit_transform(df, datetime_col="date", target_col="y")
print(monthly.head())

# Perfect symmetric aggregation
yearly_back = aligner.aggregate(monthly, freq="1y")
print("Roundtrip OK:", (yearly_back["y_1y"] - df["y"]).abs().sum() < 1e-8)

# Plot (requires plotly)
monthly.plot()  # or use .plot() on the result if extended

Supported Methods

  • uniform
  • linear
  • denton / denton-cholette
  • chow-lin, chow-lin-opt (auto ρ via maxlog/minrss)
  • litterman, fernandez

All methods guarantee C @ y_high ≈ y_low exactly.

Why aggdisagg?

  • Polars-native core (lazy-friendly)
  • Perfect consistency by construction (C/D matrices)
  • Sklearn-style + fluent API
  • Real econometric methods (Denton quadratic, Chow-Lin GLS)
  • Excellent pandas / xarray interop
  • Production quality (typed, tested, documented)

v0.2 Highlights

  • Hierarchical reconciliation (national → regional)
  • Uncertainty (bootstrap + analytic std errors)
  • Full Polars lazy + xarray DataArray I/O
  • Negative post-correction + NNLS ensemble
  • sktime / statsforecast compatible wrapper
# Hierarchical
rec = aligner.reconcile_hierarchical([nat_df, reg_df])

# Uncertainty
mean, std = aligner.predict_with_uncertainty()

# Lazy + xarray
lazy_high = aligner.fit_transform(lazy_df)
xa = aligner.to_xarray(high_df)

See examples/quickstart.py for complete gallery.

Development & Publishing

uv sync --all-extras
uv run pytest
uv run python examples/quickstart.py
uv build
# twine or uv publish

License

MIT


Built for data scientists who want temporal frequency conversion that just works.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aggdisagg-1.0.4.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aggdisagg-1.0.4-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file aggdisagg-1.0.4.tar.gz.

File metadata

  • Download URL: aggdisagg-1.0.4.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aggdisagg-1.0.4.tar.gz
Algorithm Hash digest
SHA256 cf8b104a9d0870b14008b522f56955727c04c509e1ee039d5609a71fff4d50be
MD5 1c7d6e05749b8f1fb62b7f543226db9e
BLAKE2b-256 bfd0c5d4296676d4e8caed16cd2e27b1737a6a3d84d61312cc285a4b4d483fa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for aggdisagg-1.0.4.tar.gz:

Publisher: publish.yml on southu/aggdisagg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aggdisagg-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: aggdisagg-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aggdisagg-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d857aee83368963549152fa5d7b32280873ca2510ee20e618adc7e7606b8a209
MD5 0d7ba059b0aa06ef74092b729bcd069b
BLAKE2b-256 f416fac337eeca07c636d9346fa34c4aef61378c20a133302ae6d6e9c66e8630

See more details on using hashes here.

Provenance

The following attestation bundles were made for aggdisagg-1.0.4-py3-none-any.whl:

Publisher: publish.yml on southu/aggdisagg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page