polars-hash
raw JSON → 0.5.6 verified Fri May 01 auth: no python
A Python library providing stable non-cryptographic and cryptographic hashing functions for Polars DataFrames. Version 0.5.6 supports algorithms like xxhash, murmurhash3, farmhash, SHA3 SHAKE128, UUID5, and H3 spatial index. It integrates directly into Polars expressions via `hash_` prefix. Maintained, with frequent releases.
pip install polars-hash Common errors
error AttributeError: module 'polars_hash' has no attribute 'hash_xxh3' ↓
cause Older version of polars-hash does not include xxh3 (added in 0.5.2).
fix
Upgrade to >=0.5.2:
pip install polars-hash>=0.5.2. error ImportError: cannot import name 'hash_xxh3' from 'polars_hash' ↓
cause Trying to import individual functions incorrectly. The library does not export function names at package level.
fix
Use
polars_hash.hash_xxh3(...) directly without importing the function. Correct usage: import polars_hash; polars_hash.hash_xxh3(...). error TypeError: hash_uuid5() missing 1 required positional argument: 'namespace_uuid' ↓
cause hash_uuid5 requires a namespace UUID as first argument.
fix
Provide a UUID string:
polars_hash.hash_uuid5('6ba7b810-9dad-11d1-80b4-00c04fd430c8', 'text'). Warnings
breaking Version 0.5.0 bumped Polars dependency to >=1.32.0. Older code using Polars <1.32.0 will fail to import. ↓
fix Upgrade Polars to >=1.32.0, or pin polars-hash to <0.5.0.
deprecated Prior to 0.4.9, the library used `polars.type_aliases` which is deprecated. Old custom serialisation or alias-dependent code may break. ↓
fix Upgrade to >=0.4.9 and remove any use of `polars.type_aliases`.
gotcha Hash functions return columns of type `UInt64` for non-cryptographic hashes and `Utf8` for cryptographic/special hashes (e.g., UUID5, SHA3). Mixing may cause type errors in expressions. ↓
fix Cast results explicitly: `.cast(pl.UInt64)` or `.cast(pl.Utf8)` as needed.
gotcha The `hash_uuid5` function requires a namespace UUID as first argument; omitting it will raise a `TypeError`. ↓
fix Provide a valid namespace: `polars_hash.hash_uuid5('namespace_uuid', 'text')`.
Imports
- hash_xxh3
import polars_hash - hash_murmurhash3
import polars_hash - hash_farmhash
import polars_hash
Quickstart
import polars as pl
import polars_hash
df = pl.DataFrame({'text': ['hello', 'world']})
df_with_hash = df.with_columns(
polars_hash.hash_xxh3('text').alias('hash_xxh3'),
polars_hash.hash_murmurhash3('text').alias('hash_murmur')
)
print(df_with_hash)