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({"hoist_pressure1": [101.3, 98.7]}),
    units={"hoist_pressure1": u.kPa},
)

velocity = frame.col("distance") / frame.col("time")  # UnitExpr; unit propagates
frame = frame.with_columns(velocity=velocity)
from datetime import timedelta
import modus

result = (
    modus.FrameTransform()
    .add_grouper(modus.DataGap("chunk", gap_seconds=60))
    .add_grouper(modus.EventSequence("body_up_event", source="dump_body_up_sts", value=1, within="chunk"))
    .add_cleaner(modus.Interpolate("hoist_pressure1_kpa", within="chunk"))
    .add_filter(modus.SuppressLeadingEvent("body_up_event", within_column="chunk"))
    .add_filter(modus.SuppressTrailingEvent("body_up_event"))
    .group_by("chunk", "body_up_event")
    .add_aggregation(modus.Mean("hoist_pressure1_kpa", output_name="mean_hoist_pressure1_kpa"))
    .add_aggregation(modus.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

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.DerivationRegistry.register("state_inference")
class StateInferenceDerivation(modus.Derivation):
    ...

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

Development

pip install -e .[dev]
pytest

Licence

MIT — 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.0a1.tar.gz (110.5 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.0a1-py3-none-any.whl (63.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modus_py-0.1.0a1.tar.gz
  • Upload date:
  • Size: 110.5 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.0a1.tar.gz
Algorithm Hash digest
SHA256 d84b96381f8d329404294e1946faef55048e2b961dc537aad2b31495e5272fce
MD5 eae29c89ab305d540db1271680f53c41
BLAKE2b-256 4976884e713258cd94542319e3c06eef01317d840679f8c5079cae37a04acb58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: modus_py-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 63.7 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.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 59db7c7ec1f64a12602e2855dd8d34cc7cdfa060adbc4ec5b70c10f40497eb44
MD5 44438b50f64f21ab579e0b8bb75637b6
BLAKE2b-256 2830bd8b670c63e3b73bc5e2356b1458addd772d84209d35229c0a444662ae73

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