Skip to main content

polars_rng

Random number generation in Polars.

Usage

All random number generators are implmented as Polars expressions and can be used anywhere that expressions are allowed, including in lazy contexts.

import polars as pl
import polars_rng as prng

# simulate data from a linear model
# y = x^2 + N(0, 3^2)
(
    pl.DataFrame(dict(x = [-3, 0, 2, 3, 4, 6, 11]))
    .with_columns(
        y = prng.normal(mu = pl.col("x").pow(2), sigma = 3)
    )
)
# shape: (7, 2)
# ┌─────┬────────────┐
# │ x   ┆ y          │
# │ --- ┆ ---        │
# │ i64 ┆ f64        │
# ╞═════╪════════════╡
# │ -3  ┆ 8.623695   │
# │ 0   ┆ -7.884036  │
# │ 2   ┆ 2.864818   │
# │ 3   ┆ 5.348727   │
# │ 4   ┆ 19.721068  │
# │ 6   ┆ 37.855376  │
# │ 11  ┆ 123.532992 │
# └─────┴────────────┘


# lazily simulate from binomial
lazy = (
    pl.LazyFrame()
    .select(n_coins = pl.repeat(10, 6))
    .with_columns(
        n_heads = prng.binomial(p = .5, n = "n_coins")
    )
)

lazy
# <LazyFrame at 0x1150E94F0>

lazy.collect()
# shape: (6, 2)
# ┌─────────┬─────────┐
# │ n_coins ┆ n_heads │
# │ ---     ┆ ---     │
# │ i32     ┆ f64     │
# ╞═════════╪═════════╡
# │ 10      ┆ 4.0     │
# │ 10      ┆ 7.0     │
# │ 10      ┆ 6.0     │
# │ 10      ┆ 3.0     │
# │ 10      ┆ 2.0     │
# │ 10      ┆ 5.0     │
# └─────────┴─────────┘

Available Distributions

A full list of implmented distributions is available in the main namespace:

from polars_rng import DISTRIBUTIONS

DISTRIBUTIONS
# ['normal',
# 'uniform',
# 'bernoulli',
# 'binomial',
# 'exponential',
# 'poisson',
# 'weibull',
# 'laplace',
# 'gamma',
# 'beta']

Metadata

Release files for polars_rng 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars_rng 0.1.0
File Size Uploaded
polars_rng-0.1.0.tar.gz 28.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polars_rng 0.1.0
File Interpreter ABI Platform
polars_rng-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.0 MB

Release files / polars_rng-0.1.0.tar.gz

Download URL polars_rng-0.1.0.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9092b5685692794d4aa7a4e16c96d11d19b194bed5a22593a8c2e37363c343fe
BLAKE2b-256 checksum
How to use checksums
468ffd7120d7fd84723dc5433c3ca1e9555c1f60c35439729fe15faee9af8682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / polars_rng-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL polars_rng-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 4.0 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
4dda309af180fa49d93b6f5e59fd0f04e05cdbf5f2dd659fde8049214f5b6adc
BLAKE2b-256 checksum
How to use checksums
dbc94d992296b04ba2c82664a6ab1a6c5fb6d342ce64dbcad1d9845976363b89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page