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)

┌────────┬─────────┬───────┬─────────┐ │ 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.2.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.2-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polars_ethan-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 d3ab4888a94f519a78635ae0b41a86418031b29d0f195b408175c40a021b95a1
MD5 dba91d7b98b22542c6313c943a039325
BLAKE2b-256 9b4d71408d3a2149f73053335ee4b421cdb3ca92fbd4f7520488ccba5e7e5cb4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_ethan-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d58e4fcf6139db279c7d7eb4a25254a4317406fb38d95162925828de2234d4af
MD5 dc1440a3810030077f01043e686153e9
BLAKE2b-256 cdcd5246a58e5d20f91842657b55feb42047731ab9fb4cea40d8e3e0db812140

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