Skip to main content

Personal Exposure Health Registry

Project description

compehndly (Python)

Architecture (Polars-First)

This package now follows a two-layer execution model for derived variables:

  1. compehndly.polars.kernels
  • Polars-native series kernels for external map_batches usage.
  • Contract: kernel(*series: pl.Series, **params) -> pl.Series
  1. compehndly.polars.adapters
  • Frame adapters that apply kernels to:
    • polars.DataFrame (eager kernel path)
    • polars.LazyFrame (expression path)

Public Entry Points

External integrations (already have a lazy orchestrator like apply_map):

from compehndly import get_map_fn

map_fn = get_map_fn("summation", all_required=True)

For config/YAML path-based loading, use stable wrappers in compehndly.entrypoints:

map_fn: compehndly.entrypoints.summation
# or
map_fn: compehndly.entrypoints.normalize_specific_gravity

Direct usage (you want this package to add a derived column):

from compehndly import with_derived_column

out = with_derived_column(
    frame=df_or_lf,
    function_name="summation",
    input_columns=["a", "b"],
    output_column="sum_col",
    all_required=True,
)

# For non-commutative functions use a named mapping
out = with_derived_column(
    frame=df_or_lf,
    function_name="normalize_specific_gravity",
    input_columns={"measured": "measurement_col", "sg_measured": "sg_col"},
    output_column="normalized",
    sg_ref=1.024,
)

Discover available functions:

from compehndly import list_functions

print(list_functions())

Direct series/expression application:

from compehndly import apply

out_series = apply("summation", df["a"], df["b"], all_required=False)
out_expr = apply("summation", pl.col("a"), pl.col("b"), all_required=False)

# Named data kwargs are supported
out_named = apply(
    "normalize_specific_gravity",
    measured=df["measured"],
    sg_measured=df["sg_measured"],
    sg_ref=1.024,
)

# Flexible kwargs-only fallback order
out_coalesced = apply(
    "coalesce_by_priority",
    primary=df["primary"],
    secondary=df["secondary"],
    fallback=df["fallback"],
    priority=("primary", "secondary", "fallback"),
)

Current Scope

The pattern is applied to:

  • derived_variables.summation
  • derived_variables.correction
  • derived_variables.imputation

Cross-Language Conformance

Shared test vectors live in:

  • shared/conformance/derived_variables_cases.json

Python and R should both execute this same file to verify parity. The Python runner is in:

  • python/tests/test_conformance_shared_vectors.py

Contributor Workflow (Two Steps)

Add one module in compehndly.derived_variables and do only:

  1. Implement one kernel:
  • def my_kernel(*series: pl.Series, scalar_a: float, ...) -> pl.Series
  1. Implement one expression builder:
  • def my_expr(*exprs: pl.Expr, scalar_a: float, ...) -> pl.Expr

Then expose one of:

FUNCTION_SPEC = DerivedFunctionSpec(
    name="my_function",
    kernel=my_kernel,
    expr_builder=my_expr,
)
FUNCTION_SPECS = [
    DerivedFunctionSpec(...),
    DerivedFunctionSpec(...),
]

compehndly.api auto-discovers FUNCTION_SPEC / FUNCTION_SPECS, so there is no central registry file to edit.

No per-function adapter wrappers are required.

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

compehndly-0.0.1a3.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

compehndly-0.0.1a3-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file compehndly-0.0.1a3.tar.gz.

File metadata

  • Download URL: compehndly-0.0.1a3.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for compehndly-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 6e980bc389b4b09481e1f597241d51a19e72c0684544b564cd3c68268234d96c
MD5 4d313855768096fc1b71ea3f8105da4c
BLAKE2b-256 6ff0335771ea6d7a1453352c1f345bb1780b466c7b2a0339b3042ea1061b068e

See more details on using hashes here.

Provenance

The following attestation bundles were made for compehndly-0.0.1a3.tar.gz:

Publisher: publish.yml on eu-parc/compehndly

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

File details

Details for the file compehndly-0.0.1a3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for compehndly-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 5452b9aa0300332a9d9905d1820c3b67da5a1256c73efc494ceebd7f49c2054a
MD5 4fd289939daeae93dbf33d6780d7443c
BLAKE2b-256 4b6f45ba6724e4f2a3cfa878ef80788ca8f9f1c740168f45598669f91c3dc118

See more details on using hashes here.

Provenance

The following attestation bundles were made for compehndly-0.0.1a3-py3-none-any.whl:

Publisher: publish.yml on eu-parc/compehndly

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