Skip to main content

Polars plugin for generating random distributions

Project description

polars-random

Polars plugin for generating random distributions.

Description

polars-random is a Rust plugin for the Polars DataFrame library that provides functionality to generate random numbers through a new dataframe namespace called "random". It supports generating random numbers from various distributions such as uniform, normal, and binomial.

You can set seeds, and pass the parameters as polars expressions or column names (as strings).

Installation

To use polars-random, install it using your favourite tool:

uv add polars-random
poetry add polars-random
pip install polars-random

Usage

For every available distribution, parameters can be passed as polars expressions or native python objects (int, float, string...).

Here are some examples of how to use the polars-random plugin for generating uniform distributions:

import polars as pl
# This will automatically register .random
# in pl.DataFrame namespace
import polars_random

df: pl.DataFrame = ...

If we want to generate a new uniform column called rand based on some parameters:

(
    df
    .random.rand(
        low=1_000.,
        high=2_000.,
        name="rand",
    )
)

We can also add a seed and make the generation reproducible. In the following case, we are using default parameters (low=1. and high=1.) and generating a uniform distribution called rand_seed:

(
    df
    .random.rand(
        seed=42, 
        name="rand_seed",
    )

If we want custom parameters, we can use polars expressions. Let's say we have two columns called custom_low and custom_high. For generating a new column, we can use either the expression pl.col("custom_low") or a python string "custom_low":

(
    df
    .random.rand(
        low=pl.col("custom_low"),
        high=pl.col("custom_high"),
        name="rand_expr",
    )
    .random.rand(
        low="custom_low",
        high="custom_high",
        name="rand_str",
    )
)

Distributions

Uniform distribution

import polars as pl
import polars_random

df: pl.DataFrame = ...

random_series = (
    df
    .random.rand(low=1_000., high=2_000., name="rand")
    .random.rand(seed=42, name="rand_seed")
    .random.rand(
        low=pl.col("custom_low"),
        high=pl.col("custom_high"),
        name="rand_expr",
    )
    .random.rand(
        mean="custom_low",
        std="custom_high",
        name="rand_str",
    )
)

Normal Distribution

import polars as pl
import polars_random

df: pl.DataFrame = ...

random_series = (
    df
    .random.normal(mean=3., std=2., name="normal")
    .random.normal(seed=42, name="normal_seed")
    .random.normal(
        mean=pl.col("custom_mean"),
        std=pl.col("custom_std"),
        name="normal_expr",
    )
    .random.normal(
        mean="custom_mean",
        std="custom_std",
        name="normal_str",
    )
)

Binomial Distribution

import polars as pl
import polars_random

df: pl.DataFrame = ...

random_series = (
    df
    # Mandatory parameters n and p
    .random.binomial(n=100, p=.5, seed=42, name="binomial")
    .random.binomial(
        n=pl.col("custom_n"),
        p=pl.col("custom_p"),
        name="binomial_expr",
    )
    .random.binomial(
        n="n",
        p="p",
        name="binomial_str",
    )
)

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_random-0.3.2.tar.gz (82.0 kB view details)

Uploaded Source

Built Distributions

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

polars_random-0.3.2-cp38-abi3-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_random-0.3.2-cp38-abi3-win32.whl (3.4 MB view details)

Uploaded CPython 3.8+Windows x86

polars_random-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

polars_random-0.3.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (4.6 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

polars_random-0.3.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (4.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

polars_random-0.3.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (4.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

polars_random-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

polars_random-0.3.2-cp38-abi3-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_random-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file polars_random-0.3.2.tar.gz.

File metadata

  • Download URL: polars_random-0.3.2.tar.gz
  • Upload date:
  • Size: 82.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.8.2

File hashes

Hashes for polars_random-0.3.2.tar.gz
Algorithm Hash digest
SHA256 80c835ebb6c4377c911a71d9c02aa52224a1546b0375610811aa8c62b6e5183c
MD5 77cdd1df72ffc10d63f5861896c810e3
BLAKE2b-256 40a8c2384381c1b6735b40efae7cdf917e082bd075264fef388d93d0579f23a2

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 22c2e07dfc2f7279638e25aea9e564fda309abaf4bb3d2bb95380a5c29212c61
MD5 c151c754a7192375dbf324d26e5b6ff2
BLAKE2b-256 9991031648867f2b032942e5763141713bb3d0e302d22b757af46bb40f1999fb

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-win32.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 41fdfe674a4bf161ae2c8f07504acd564073bb423d3aec64ca3da1f738d9e958
MD5 4e5e7d073cd21c16080b82dd61aa444f
BLAKE2b-256 d4105442ace4c1b40510eb61709f8b58f1270b9ce2ca4e4b836e1e5515168e57

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3eb75cae3d031f9b17efb537bc9116da392976cc92c4af1b24704672a537df1
MD5 ac924f0728fdd076eff08020d9e41bea
BLAKE2b-256 e426ac20fc9e14cf43c949f0f5865ef3d0d43948bb2d951f41d27d440aa3e001

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 cfddbb395a0acd536d71e3ffde874c64c5696c413aff20bc25f4f22461b5113b
MD5 7e317b094138fa5838af4fa4c9cb2db7
BLAKE2b-256 7e388d07dcf0fc336ae0d74e7c34dafc378cab4ee19b3a83188a2a9bfc87806e

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fafc7f5c8313de0bd18238da2d582b4db0db9d8c2f44b4bdc999da19bfcc8d39
MD5 39b9ff400c1b88d51a79963b88e42dcf
BLAKE2b-256 73b5f15e4cc3bc8158ca20a1b9cf37dfed0b4886407384aef69c7e3cf2890aad

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 c6a00346d948bb58d7a46ac7c108589716b36c747f761b6ffe060a67d8dbd1a7
MD5 262bddd8d6f6ab6ee9f7b4612f9bd0dc
BLAKE2b-256 e52ae561f20ff643fd9f07e05918ffccf504083685f5326278adce3664feec2d

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dbbb9cf9284daf2440fe7a956be4082a17ad15ed8fd5213ee371b46a11258d9a
MD5 b64ba2db20ad6d856ebc221e7390f81d
BLAKE2b-256 c0b250a0d6cc0c144886759724b6c6f4c6446015a315b56ee15727f6844c7b45

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aaf6f842e9e6931e9b25d7ab6c39ae7f912c6b0e7a997b2497b16d295b3f32d9
MD5 80a10e1c83f50bddb81263a7ff650626
BLAKE2b-256 92462d9a40c72e5764aa3c933cb26fe709e0f94f00d5a9b60a80ae5fccfdcab0

See more details on using hashes here.

File details

Details for the file polars_random-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_random-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 280f92ca13203e9b10e405e69b1c366712d4421368c143b50ff456cddbb3f7d1
MD5 5e3500cef2db259ed2c3b8971513c520
BLAKE2b-256 dbc0137717f52fb7b4181be85232211be6381ca23aac1541aa14bec224924f0b

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