Skip to main content

Fast Polars functions that Ethan likes to use.

Project description

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 as we would 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.3.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.3-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for polars_ethan-0.2.3.tar.gz
Algorithm Hash digest
SHA256 2767f1a895b5d95bdbedab47012c36883b71a397b529e2efd8faf9d0369b6c3b
MD5 259095fcec382570be9ee248d1e3af9a
BLAKE2b-256 68ea4a1e798b47d8381318acd3ab1a7f0a66d3b72319cb2e0323b627f857c2cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_ethan-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1ee428d22c874e01019bfd9e8122e202eefecc651f68613146ad9062697d9e35
MD5 deda5cfcbfd0edbc7f7cd5a99f6060a6
BLAKE2b-256 fb1468bc80de89daf585e991c0a8cb1d367a3531209b3cae83176fefbb3bcf82

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