Skip to main content

Schema-driven, unit-aware Polars transform engine.

Project description

modus

Schema-driven, unit-aware Polars transform engine.

modus pairs ModusFrame — a Polars DataFrame with per-column Astropy unit metadata — with FrameTransform, a builder-pattern engine for expressing timeseries transform pipelines (grouping, cleaning, deriving, filtering, and aggregating) declaratively, while keeping unit metadata accurate throughout.

Installation

pip install modus-py

Quick start

import astropy.units as u
import polars
import modus

frame = modus.ModusFrame(
    data=polars.DataFrame({"pressure_kpa": [101.3, 98.7]}),
    units={"pressure_kpa": u.kPa},
)

velocity = frame.col("distance") / frame.col("time")  # UnitExpr; unit propagates
frame = frame.with_columns(velocity=velocity)
import modus
from modus.transform.ops import aggregations, cleaners, groupers, suppressors

result = (
    modus.FrameTransform()
    .add_grouper(groupers.DataGap("chunk", gap_seconds=60))
    .add_grouper(groupers.EventSequence("body_up_event", input_column="sts", value=1, within="chunk"))
    .add_cleaner(cleaners.Interpolate("pressure_kpa_kpa", within="chunk"))
    .add_suppressor(suppressors.SuppressLeadingEvent("body_up_event", within="chunk"))
    .add_suppressor(suppressors.SuppressTrailingEvent("body_up_event", within="chunk"))
    .group_by("chunk", "body_up_event")
    .add_aggregation(aggregations.Mean("pressure_kpa_kpa", output_name="mean_pressure_kpa_kpa"))
    .add_aggregation(aggregations.Duration(output_name="body_up_duration_s"))
    .apply(frame)
)

labelled = result.labelled      # ModusFrame -- timeseries with grouper columns added
aggregated = result.aggregated  # ModusFrame -- one row per (chunk, body_up_event) group

Documentation

See docs/ for the full reference: ModusFrame/UnitExpr, the unit registry, FrameTransform's execution model and pre-flight validation, each operation family (groupers, cleaners, derivations, suppressors, group masks, event views, aggregations), the declarative TransformSpec schema, and JSON serialisation.

Custom units

modus ships an extensible unit registry, in the same spirit as Astropy's own enabled-units model:

import astropy.units as u
import modus

modus.units.registry.register("kgcm2", u.def_unit("kgcm2", 98.0665 * u.kPa))

Custom derivations and aggregations

Both extension points are plugin registries keyed by name, so a schema or manifest layer built on top of modus can construct bespoke operations from declarative configuration without importing analytic-specific Python:

import modus

@modus.transform.DerivationRegistry.register("state_inference")
class StateInferenceDerivation(modus.transform.Derivation):
    ...

@modus.transform.AggregationRegistry.register("weighted_percentile")
class WeightedPercentile(modus.transform.Aggregation):
    ...

Development

pip install -e .[dev]
pytest

Licence

BSD-3-Clause — see LICENSE.

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

modus_py-0.1.0a3.tar.gz (675.9 kB view details)

Uploaded Source

Built Distribution

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

modus_py-0.1.0a3-py3-none-any.whl (356.1 kB view details)

Uploaded Python 3

File details

Details for the file modus_py-0.1.0a3.tar.gz.

File metadata

  • Download URL: modus_py-0.1.0a3.tar.gz
  • Upload date:
  • Size: 675.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for modus_py-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 c26f4b2003446a9632020bdec314c1b0aefc9210c2502f374d1bef19b29eaed7
MD5 5e00aa6e03eba20e0e7f53169c347c33
BLAKE2b-256 a1e385fb12380104e668ac683cdb050cc502a3c13b8ae25563ecacfe2717e007

See more details on using hashes here.

File details

Details for the file modus_py-0.1.0a3-py3-none-any.whl.

File metadata

  • Download URL: modus_py-0.1.0a3-py3-none-any.whl
  • Upload date:
  • Size: 356.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for modus_py-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 4817013505455b81641072503c320a6b23442dbfb8b730bf15938e9f565480ab
MD5 bac200cfea8298699ba3a69fa205daac
BLAKE2b-256 bb531e6b03c151254a4066351786db68278ac4ba3d727561b34e8d627c7d133c

See more details on using hashes here.

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