This plugin provides stable hashing functionality across different polars versions.
๐ Documentation โ every expression, its input and output types, and its arguments.
Examples
Cryptographic Hashers
import polars as pl
import polars_hash as plh
df = pl.DataFrame({
"foo":["hello_world"]
})
result = df.select(plh.col('foo').chash.sha256())
print(result)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ foo โ
โ --- โ
โ str โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก
โ 35072c1ae546350e0bfa7ab11d49dc6f129e72ccd57ec7eb671225bbd197c8f1 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Non-cryptographic Hashers
df = pl.DataFrame({
"foo":["hello_world"]
})
result = df.select(plh.col('foo').nchash.wyhash())
print(result)
โโโโโโโโโโโโโโโโโโโโโโโโ
โ foo โ
โ --- โ
โ u64 โ
โโโโโโโโโโโโโโโโโโโโโโโโก
โ 16737367591072095403 โ
โโโโโโโโโโโโโโโโโโโโโโโโ
result = df.select(plh.col('foo').nchash.farmhash64())
print(result)
โโโโโโโโโโโโโโโโโโโโโโโโ
โ foo โ
โ --- โ
โ u64 โ
โโโโโโโโโโโโโโโโโโโโโโโโก
โ 15605398435621216523 โ
โโโโโโโโโโโโโโโโโโโโโโโโ
result = df.select(plh.col('foo').nchash.farmhash32())
print(result)
โโโโโโโโโโโโโโ
โ foo โ
โ --- โ
โ u32 โ
โโโโโโโโโโโโโโก
โ 1719156559 โ
โโโโโโโโโโโโโโ
result = df.select(plh.col('foo').nchash.cityhash128())
print(result)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ foo โ
โ --- โ
โ u128 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก
โ 133423608296839006301901834072762183026 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
result = df.select(plh.col('foo').nchash.gxhash64())
print(result)
โโโโโโโโโโโโโโโโโโโโโโโ
โ foo โ
โ --- โ
โ u64 โ
โโโโโโโโโโโโโโโโโโโโโโโก
โ 2180020304351407825 โ
โโโโโโโโโโโโโโโโโโโโโโโ
cityhash32() and cityhash64() return the values printed above for farmhash32()
and farmhash64(). That is expected: FarmHash reuses CityHash for short input, and
hello_world is 11 bytes. See
the CityHash reference.
The GxHash expressions need a CPU with AES instructions and have no software fallback.
Every x86, x86-64 and aarch64 wheel is built for them; there are no linux-armv7 or
linux-ppc64le wheels from 0.8.0 on, because GxHash cannot be built for either. See
the GxHash reference.
Geo Hashers
df = pl.DataFrame(
{"coord": [{"longitude": -120.6623, "latitude": 35.3003}]},
schema={
"coord": pl.Struct(
[pl.Field("longitude", pl.Float64), pl.Field("latitude", pl.Float64)]
),
},
)
df.with_columns(
plh.col('coord').geohash.from_coords().alias('geohash')
)
shape: (1, 2)
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ coord โ geohash โ
โ --- โ --- โ
โ struct[2] โ str โ
โโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโก
โ {-120.6623,35.3003} โ 9q60y60rhsgg โ
โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
pl.select(pl.lit('9q60y60rhs').geohash.to_coords().alias('coordinates'))
shape: (1, 1)
โโโโโโโโโโโโโโโโโโโโโโโโโ
โ coordinates โ
โ --- โ
โ struct[2] โ
โโโโโโโโโโโโโโโโโโโโโโโโโก
โ {-120.6623,35.300298} โ
โโโโโโโโโโโโโโโโโโโโโโโโโ
H3 Spatial Index
df = pl.DataFrame(
{"coord": [{"longitude": -120.6623, "latitude": 35.3003}]},
schema={
"coord": pl.Struct(
[pl.Field("longitude", pl.Float64), pl.Field("latitude", pl.Float64)]
),
},
)
df.with_columns(
plh.col('coord').h3.from_coords().alias('h3')
)
shape: (1, 2)
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ coord โ h3 โ
โ --- โ --- โ
โ struct[2] โ str โ
โโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโก
โ {-120.6623,35.3003} โ 8c29adc423821ff โ
โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโ
Time Hasher
Bins timestamps into variable-precision sliding windows of time, so rows that fall in the same window share a hash. Timestamps must lie between 1970-01-01 and 2098-01-01. A higher precision means a shorter window: 10 covers about 4 seconds, 8 about 4 minutes.
Precision may be 1 to 32, but past about 18 the hash stops changing for present-day timestamps and the extra characters are padding. The exact point depends on the date: timestamps close to 1970 keep splitting to about 21, far-future ones run out sooner.
from datetime import datetime
df = pl.DataFrame({"datetime": [datetime(2017, 2, 21, 20, 15, 13)]})
df.with_columns(
plh.col('datetime').timehash.from_datetime().alias('timehash')
)
shape: (1, 2)
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ datetime โ timehash โ
โ --- โ --- โ
โ datetime[ฮผs] โ str โ
โโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโก
โ 2017-02-21 20:15:13 โ afcccc0e1b โ
โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
pl.select(pl.lit('afcccc0e1b').timehash.to_datetime().alias('datetime'))
shape: (1, 1)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ datetime โ
โ --- โ
โ datetime[ฮผs, UTC] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก
โ 2017-02-21 20:15:11.292315 UTC โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
pl.select(pl.lit('afcccc0e1b').timehash.neighbors().alias('neighbors'))
shape: (1, 1)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ neighbors โ
โ --- โ
โ struct[2] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก
โ {"afcccc0e1a","afcccc0e1c"} โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Create hash from multiple columns
df = pl.DataFrame({"foo": ["hello_world"], "bar": ["today"]})
result = df.select(plh.concat_str("foo", "bar").chash.sha256())
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_hash-0.8.0.tar.gz.
File metadata
- Download URL: polars_hash-0.8.0.tar.gz
- Upload date:
- Size: 81.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c86f2e18b08a5919fff52fe7c57208b4219807cf1ab136fcb6710ed116d6119
|
|
| MD5 |
130fa5aafc6d117befb419ebb227929f
|
|
| BLAKE2b-256 |
bcee5fcc3a62c1a8aa7e167e9f58987a95d4f90e139b484a881e285934ded113
|
File details
Details for the file polars_hash-0.8.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: polars_hash-0.8.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 6.9 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
640d5be11327942f2c681da678fb1ccd54fa789166bfc1406c6ef8157a2af3f2
|
|
| MD5 |
e09a81646dd1693933e742cfe752521c
|
|
| BLAKE2b-256 |
fe17564ef1f07da76dc911f503c11717f3ab462200b66147d12111e71959ec4c
|
File details
Details for the file polars_hash-0.8.0-cp310-abi3-win32.whl.
File metadata
- Download URL: polars_hash-0.8.0-cp310-abi3-win32.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.10+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16a870a08dbf55ef3b2368ee52157fcb71087d336ced817f06b085c8487de59d
|
|
| MD5 |
8b183a151e4d0e0c83df2922e9e93066
|
|
| BLAKE2b-256 |
48b635f73146e297f30a7e04933ea8fd52e865c175c3cd126f39afc80235bd35
|
File details
Details for the file polars_hash-0.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: polars_hash-0.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.7 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17491ae25323cf06e68e0642ae3469aa7a2ad756462410da8220f4fc4dbab8e0
|
|
| MD5 |
67b36aaeec3230a6472f020874cc47e5
|
|
| BLAKE2b-256 |
c89780ecd71dc443ef9ca12a2ee193afa9fdc93e7f3322c700bc070acc53a95a
|
File details
Details for the file polars_hash-0.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: polars_hash-0.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 6.1 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef3b7e4d80d4aaa2bddcfda3cd7895eb4236262ed5daf7628a845ba7d590a11f
|
|
| MD5 |
294800d8e22ed4d4e0d719423deed9ae
|
|
| BLAKE2b-256 |
3b43747fbd05261128584b1f9d9dd2a1e12927830937132da70bc4f38a1194d6
|
File details
Details for the file polars_hash-0.8.0-cp310-abi3-manylinux_2_12_i686.manylinux2010_i686.whl.
File metadata
- Download URL: polars_hash-0.8.0-cp310-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
- Upload date:
- Size: 7.3 MB
- Tags: CPython 3.10+, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5980e5c24edb43aa9410d156f1933dff35898f7997d701555bf7f5bc171d995d
|
|
| MD5 |
9f491595d667d0115fc10d9e03e5d0b5
|
|
| BLAKE2b-256 |
308da909ea9b7da4de6f73e98e58cdffb8d19e20775fb1a8e93ff462f46f4322
|
File details
Details for the file polars_hash-0.8.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_hash-0.8.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.8 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66940fad5742cb2d3074eda47db21c507c988d5f2e76dbd5501373f424020702
|
|
| MD5 |
f7608275a32c550a9483cc32a8f9527a
|
|
| BLAKE2b-256 |
41c9b79db3b5ea113c2d0d875699bfc40b835431a1ac01dd2dd02400f82337e7
|
File details
Details for the file polars_hash-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: polars_hash-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 6.6 MB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65cee1d1f961b1a07fc8e6a42f2fe64f4f2b7e595611e88a22257b7d9827f166
|
|
| MD5 |
05ea87072cd3e689c1fd022bbe15d966
|
|
| BLAKE2b-256 |
b42ed54228122917644df2216067f817284d093906f8a1148b859cdd1d53f998
|