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.1.tar.gz (81.3 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.1-cp38-abi3-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+Windows x86

polars_random-0.3.1-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.1-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.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (4.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

polars_random-0.3.1-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.1-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.1-cp38-abi3-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_random-0.3.1-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.1.tar.gz.

File metadata

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

File hashes

Hashes for polars_random-0.3.1.tar.gz
Algorithm Hash digest
SHA256 a859215fd403ace612b88c06807f2d5e468b15b62cdea33917d948317986e787
MD5 e66ca374c68591afd6bf764ef42d6bfb
BLAKE2b-256 3e63c29ba894e09b80db4ae7607bc3b22484ab5ed2a4d3bc12f62bf9c6c5b52d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3b115c4561c2b4b883826ff9d21232b6103f84f5801bb9b4ebee9351532c7264
MD5 11d72eaf8454ddf09440e9b136714f2e
BLAKE2b-256 f3d51118495a99f4507dbfedf4fd55ccea41b445dc02ed2acdcea65d88315d8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 ab998785875469c81b97b1ebbe4f5a342b48a8a0c94a7325c4855da129c3437e
MD5 18aabdb2a8596c0ae413841f1d6bd46c
BLAKE2b-256 c10175b42f7a258dd61e2d686b9fda0be317f62482e29dda435e71b26e732b2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 91bc6b8d9124bc7f02c1be706067945a0751ef57ba308e242f578e42e60998d1
MD5 88d5869b37568ee750858d4ddfe84a2c
BLAKE2b-256 0c24bf4b11ebd67eb7db2ca79bf293bc26109c3090df0d32191ed5b0a61fb7f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 571956bd5ce2189f7ee8aa0644541bfa604287370faf97377589f2baf548c632
MD5 38a7f6ef623b51afd2efeab56f0620fb
BLAKE2b-256 6f16c7fa72fc158061385b5a3bca8b9c4e2e04df5d666a0bfef55e94bc6a7af6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 9a138ed0b0e6a7fb85b61991fabe89a0af04357f567372dbb9cd633256428ead
MD5 3dc3a4b56a48d7fc1a6621dc3350e810
BLAKE2b-256 b3a89b8435a94c8e83d73b39b0b1ecb59bce7e89017393a5fda85439486e5c76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 3d6134d4c7f35b61d9493f2f2b5b11aea29b8f13fe47ce52a8e2f23ff1df78ac
MD5 cef6b9364dcf47335c4ac9b75187b9a9
BLAKE2b-256 e20aca42adc426fc38b59221a6da817cad679e63d4caf813c0566b5f75debb30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 debdf01e7161af73223326cdde0e6f12809953a3bffbdb687a14e28969687d75
MD5 d2b465158c71b979f8b40b74089fda6c
BLAKE2b-256 c22c9fbf4355dd00a0e7ba858063cfbc74294638e7262e9febae7a8568fc6066

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b4ece9f3bf97171328e4fc2d9cc8bc2a46ce848e9282c8f4d2caec05a164503c
MD5 8abcd59f972ba93c37a91b60ca4cf5a0
BLAKE2b-256 8b57a5df36afa4d5dfb251001d636c38bc177aeb1b3387b1490f1b7a67349256

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_random-0.3.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e546c21364d4145aab23e7bd452bdeca099e49708db9e3b3b69583dca965ea16
MD5 f97e41e232cc57d580cf1553fadb6cec
BLAKE2b-256 e8492df83cefdb25e46d25b61484562db112d241a4d4a74deda775b0701db48a

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