Skip to main content

Fast Polars functions that Ethan likes to use.

Project description

polars-ethan is a Python library that adds useful functions for use with Polars. This is also my first published package, so it is a good exercsie.

Features

Demean

The demean function subtracts the mean from each non-NaN value in an array, preserving NaN values.

import polars as pl
from ethanpolars import demean

# Sample data...
cameras = pl.DataFrame(
    {
        "brand": ["Leica", "Leica", "Leica", "Mamiya", "Mamiya", "Mamiya"],
        "model": ["MP", "M4", "M7", "RB67", "7II", "645 Pro"],
        "price": [6000, 10000, None, 600, 3000, 900],
    }
)

cameras = cameras.with_columns(
    pl.col('price')
    .fill_null(np.nan)
    .map_batches(demean)
    .over(pl.col("brand"))
    .fill_nan(None)
    .alias('d_price')
)

print(cameras)

Output:

┌────────┬─────────┬───────┬─────────┐
│ brand  ┆ model   ┆ price ┆ d_price │
│ ---    ┆ ---     ┆ ---   ┆ ---     │
│ str    ┆ str     ┆ i64   ┆ f64     │
╞════════╪═════════╪═══════╪═════════╡
│ Leica  ┆ MP      ┆ 6000  ┆ -2000.0 │
│ Leica  ┆ M4      ┆ 10000 ┆ 2000.0  │
│ Leica  ┆ M7      ┆ null  ┆ null    │
│ Mamiya ┆ RB67    ┆ 600   ┆ -900.0  │
│ Mamiya ┆ 7II     ┆ 3000  ┆ 1500.0  │
│ Mamiya ┆ 645 Pro ┆ 900   ┆ -600.0  │
└────────┴─────────┴───────┴─────────┘

Note how null values must be converted to NaN before being passed to the function. Generalized ufuncs do not except null values, but NaN's are fine and behave how we like.

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

polars_ethan-0.2.4.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

polars_ethan-0.2.4-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file polars_ethan-0.2.4.tar.gz.

File metadata

  • Download URL: polars_ethan-0.2.4.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.9

File hashes

Hashes for polars_ethan-0.2.4.tar.gz
Algorithm Hash digest
SHA256 5a6d393bda628c3cc89cefaed9c46f5866ec93a7669f522fec20ee5fe5364bee
MD5 01e6870e849944bdda850178fef46dd8
BLAKE2b-256 17a0e403578f0d642a7f21f0a53c46eb84aa5d554394ae5d82c0b135c31b8792

See more details on using hashes here.

File details

Details for the file polars_ethan-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for polars_ethan-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2ef911e9183abc8c8acfa04605f19252c61a71dbdf09b35c8e302313813caf65
MD5 db219020f8f3ef765a323400bcc6d188
BLAKE2b-256 e10a3f620219f4558b028c0f44fb9fd3dc59ff71658800df1d79a2c9e630e693

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