Skip to main content

High-performance n-gram generation for Polars

Project description

ngram_polars - N-Gram Generation for Polars

A high-performance Polars plugin for generating n-grams from text data in Python.

Installation

pip install ngram-polars

Basic example

import polars as pl
from ngram_polars import ngrams

df = pl.DataFrame({
    "id": [1, 2],
    "words": [
        ["the", "quick", "brown", "fox"],
        ["hello", "world"]
    ]
})

# Generate bigrams
result = df.with_columns(
    bigrams=ngrams(pl.col("words"), n_range=[2])
)

more advanced examples

# Multiple n-gram sizes
df.with_columns(
    multi_ngrams=ngrams(pl.col("words"), n_range=[1, 2, 3])
)

# Custom delimiter
df.with_columns(
    underscored=ngrams(pl.col("words"), n_range=[2], delimiter="_")
)

# Lazy evaluation
(df.lazy()
   .with_columns(
       ngrams=ngrams(pl.col("words"), n_range=[2, 3])
   )
   .collect()
)

API Reference

ngrams(expr, n_range, delimiter) Generate n-grams from a list of strings.

Parameters:

  • expr: IntoExpr - Polars expression representing a list of strings
  • n_range: list[int] - List of n-gram sizes to generate (default: [1])
  • delimiter: str - String delimiter between words (default: " ")

Returns:

  • pl.Expr - Expression that generates lists of n-gram strings

Behavior:

  • Returns a new list column containing all generated n-grams
  • Works element-wise on list columns
  • Changes the length of the output (each input list produces a new list of n-grams)
  • Supports both eager and lazy evaluation

Performance Tips

  • Use Lazy Evaluation: For large datasets, use lazy evaluation to optimize query planning
  • Batch N-Gram Sizes: Generate multiple n-gram sizes in one call when possible
  • Choose Appropriate N-Range: Only generate the n-gram sizes you actually need

Requirements

  • Python 3.10 -> 3.14
  • Polars requirement are not fully tested, tested on the latest version.
  • Compatible with both eager and lazy Polars APIs

Changes

0.1.2: Updated to Rust 1.93.1 and Polars 0.53.0 (dropped python 3.9 added 3.14)

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

ngram_polars-0.1.3.tar.gz (28.2 kB view details)

Uploaded Source

Built Distributions

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

ngram_polars-0.1.3-cp314-cp314-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.14Windows x86-64

ngram_polars-0.1.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

ngram_polars-0.1.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

ngram_polars-0.1.3-cp314-cp314-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ngram_polars-0.1.3-cp314-cp314-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

ngram_polars-0.1.3-cp313-cp313-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.13Windows x86-64

ngram_polars-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ngram_polars-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

ngram_polars-0.1.3-cp313-cp313-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ngram_polars-0.1.3-cp313-cp313-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

ngram_polars-0.1.3-cp312-cp312-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.12Windows x86-64

ngram_polars-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ngram_polars-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

ngram_polars-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ngram_polars-0.1.3-cp312-cp312-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

ngram_polars-0.1.3-cp311-cp311-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.11Windows x86-64

ngram_polars-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ngram_polars-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

ngram_polars-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ngram_polars-0.1.3-cp311-cp311-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

ngram_polars-0.1.3-cp310-cp310-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.10Windows x86-64

ngram_polars-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ngram_polars-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

ngram_polars-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

ngram_polars-0.1.3-cp310-cp310-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file ngram_polars-0.1.3.tar.gz.

File metadata

  • Download URL: ngram_polars-0.1.3.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ngram_polars-0.1.3.tar.gz
Algorithm Hash digest
SHA256 71da83af00ba399830fe1f3af0aac22bae561f6f2a55f5e68bc161abd11bb8b1
MD5 a93e71a0dacec8f7b416542448f345e2
BLAKE2b-256 e44d81ef59ec18e6da04ee65d772b328091e5ce5a41326dea55883885a21492e

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 aa5fc61bbc500d25362a74cd8c1041a0ce7b298da06c55bc81be35981400a9b6
MD5 ec73fd606c54d2eae40da9429094333e
BLAKE2b-256 5e9f99b167d170ca49d9125d2c5e8773d29aa6aeb9967593cee22b7fdb06ecc1

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 07ab8dd241515cab3e02ceb49e9d613356fbd7b6caec49bf6711b78f640f51e5
MD5 28453b2bc470c43ffdd30cb6d7a2282e
BLAKE2b-256 6079ded66cc6e171b1423302ac2770550fa6de68d232b5fa542fc552c4c43d1f

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 90287de33051267a95cb49f3ff19f101e02f452bfd61628b1dfa4562f008cbf1
MD5 331a67df6b2d86398516a36bf8f86f9f
BLAKE2b-256 ad40ae9104a15f63647dc37b2a01e266495c7972340af51177b54de4ebf4124c

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1731d0d259bb2abdc8417950b38712dfbc6e9e744ffa164e32f9a81146f3e916
MD5 27fd558151a9caf488ae93672dc36f2c
BLAKE2b-256 6f42ec1012f2bf12c3f9bb2d6171eeb1c9c09ff49f319bb73f15d49f4e13dc2a

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3ed8b878b3f1544868a3d015dca989df3516d64f6f0aa5d494c761cd63688315
MD5 6896154ab0bfc7b6bd4c29392e67102f
BLAKE2b-256 67d35244a360e6c74ee6db57efd7560a277097518c0a64c9e9163410ec755128

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3c58d58cfed91a9debe1177ef8d068b7d12d703588374b31e764ff88e4beb96f
MD5 8b640feffceb3b9533b3fd332b712eab
BLAKE2b-256 d2d818e720045e37c1b51fb3343d54648f32f1babed92730c3d193cf5b9720af

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7997f6f53924c27eb60ec77fb9c97353027d35899b5f9c976135fd534552d59c
MD5 e704452578223dc00402f9e2b8d1dcd8
BLAKE2b-256 7da296fd33ef0e8dd139cb7f814d9426af2d4d3987e321f0e6ac2a881c8c7aa0

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7f8db3fc46442740a5c1d0f1f9598e8cf11db01b6f413254c829611f74c100c0
MD5 696c4d08379d2a8a3c0a52048aaf114e
BLAKE2b-256 81bfaf4b3b20c00774a066fd38ae452e111d776acdb055a48c3cc32e1880cf73

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 50048017addfee1e44a979442631386123ccd5a339000213bee9dd6a9762e5a5
MD5 b9900745d7b2ef768957aef2f28a53f2
BLAKE2b-256 b00a9b33b8672922553dd798fe7b293449c3c0d9b8cbeb307e0ed9b099e48688

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b468c6d2ee33270048552ab9daaedd28e500340bbd576a25d157a72051115652
MD5 fbde26df2f9e77d59842c7ab0445630c
BLAKE2b-256 5a02e5418c48630d8b4f804c8387d8d6ff3a5b5557075c5f003c7006b2a23191

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 49c724227f2f55e32c15fc0a0bc52cf7a6d1b5590b44a2fb2a3fcd10eb82f1a8
MD5 b69f699d24a4b0b9af90fa2fa6457bf8
BLAKE2b-256 c75116046826a9d3e63951545bcd26560d13e66c3c6bff78a42324be2cda3d92

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f1952bdb546dc6de0059234b63fcfb830295c6a9b377a145c88227567b9fdc2
MD5 f685b7cc4904f977a44dc823c6da223d
BLAKE2b-256 57260caf43cfb392b7c621d3efecda3c24d445ab08c724e8399d39a27018939a

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e5ecc0ca575e792c516a17053cca4dc746c14af299d32baab7359e35384c8c84
MD5 63bc983c8e9ac825913f1555fb826b73
BLAKE2b-256 5ec1b3483029407ac15b3ed3c337a0181c6996fad8160f49f8c32bcc1a29b11f

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd1ccac1a335009ab336ae76470d5102621bda42a28653283a0c21ba5aacfb8f
MD5 671f41f40a66cb056f43518e66a39934
BLAKE2b-256 713d757ca4a878ba2a6fb08b6a3cee7575237da6b5d65a022ac98a6e5ff92e7c

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 137f497aa393e3973fce88766e82e71be10afe6ecd27f44d0639ba5410af6bdf
MD5 a9f5f30dd6f45f7f0f43fb177529cff8
BLAKE2b-256 d69baa3ca58d90a0c5e81117900448429976817f5a7994ec285d2ed454dd5eb6

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b048f1e02c6a7f9abd155ed16764770fbc6d144072523f30d383da4aa4b113fc
MD5 a3fccdd8f39ef162fe27fddf301ecfea
BLAKE2b-256 9914c8e40e18725082e878f703cce842602c67d0290b980a10f53cc622ce63fb

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a8ec15066c714a996ddaeab56c984b1b18eedd7510eba147a80cb52c890cecf
MD5 cac7af32c733c3438f914364c28d8b1f
BLAKE2b-256 b2b9b3317302681a28600bf52751f6a6ea60b5c229b3c8c1aee5cb76ddb5f3f1

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 45ae62d14f919d8954cde15da8265a38041b23a6d039275cbcb9cdf747dfa8d9
MD5 17985b49d3242e872458490e3c45a63e
BLAKE2b-256 f7dde95931e63e05ce6c941cafe0d7d5c5e6407976033c5ed9a42dc8b918f9f9

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5b709c6ce30c776ed23ecb4f27a7128960a6d9611b8a77c7767c0c61a3199fb
MD5 cfe899cd0d76d3d27d66d99c5714a359
BLAKE2b-256 a560ce251f45752890cf48f0a927fc44e9a92c4339532050153ffef5f690af95

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 73136b8228b1b6cb85a9e6cfcc1c3175c71ab17ab47f6aaf037239b60cbc8f01
MD5 96e51abe16148e0284575a9ed7cf3e38
BLAKE2b-256 bfcef1be698571aefd677412c4a3292f81efcc1d2c173ff8d0b582927d52806b

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8b12a5c075c17114976bd482864134fc64c468364b59de9b15601be8df20b251
MD5 11c5c9039a8dc6b801ff9ddc47833f4a
BLAKE2b-256 d8250d4524d52a026ca255c7202c654e8f4c10304bdb19befbabc84e48d4ddf1

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6fd4bbf12be3f92c6d8e3513319c89f3329da25d539c0a3f0311961f031d99ad
MD5 2e2a9ce9b5cf92e6a235d3ba047c090b
BLAKE2b-256 079529cf9fcd67ae34fbd5d7177c4aaba203288c3909d06ab274af3932a2c46a

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a15a9d0836ed2b23af91d01c89a06975d8345fd5c24cae4da5d9da53a5c7d5f7
MD5 bf52e171e41075a38978ec4b507bec75
BLAKE2b-256 c1ecc7d423383349a34ebdb53c88e0052ef5dbce32c8e6d40fe873f62f378587

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5512caae4e1f4ac67629c16e8d49bb63ae48dc8504ada57b35cf1cb1e47c035f
MD5 3ee94ea213bb8d3e123c0376217fab0a
BLAKE2b-256 57134d4780f5ebefcc4f9edef8e37455615404dc009087121bd6da58290d7182

See more details on using hashes here.

File details

Details for the file ngram_polars-0.1.3-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ngram_polars-0.1.3-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 686bff7d24c7a795c29281dc3db1fd1c3897c83b7e19101b066b2bf6939a9ed9
MD5 95bf56ae769d8b9e1a14855e1e184b44
BLAKE2b-256 a81af4c3a9a91d06d4e88d7beae392bd1e0c82a8f54db4db71a5a5a01438e7b3

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