Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ion-elgreco/polars-hash
Polars plugin for stable hashing functionality
https://github.com/ion-elgreco/polars-hash
Last synced: 4 days ago
JSON representation
Polars plugin for stable hashing functionality
- Host: GitHub
- URL: https://github.com/ion-elgreco/polars-hash
- Owner: ion-elgreco
- License: mit
- Created: 2023-10-26T13:20:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-01T13:44:44.000Z (about 2 months ago)
- Last Synced: 2025-01-11T05:13:47.900Z (11 days ago)
- Language: Python
- Size: 90.8 KB
- Stars: 59
- Watchers: 1
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-polars - polars_hash - Python package that provides stable hashing functionality across different Polars versions by [@ion-elgreco](https://github.com/ion-elgreco). (Libraries/Packages/Scripts / Python)
README
This plugin provides stable hashing functionality across different polars versions.
## Examples
### Cryptographic Hashers```python
import polars
import polars_hash as plhdf = pl.DataFrame({
"foo":["hello_world"]
})result = df.select(plh.col('foo').chash.sha256())
print(result)
┌──────────────────────────────────────────────────────────────────┐
│ foo │
│ --- │
│ str │
╞══════════════════════════════════════════════════════════════════╡
│ 35072c1ae546350e0bfa7ab11d49dc6f129e72ccd57ec7eb671225bbd197c8f1 │
└──────────────────────────────────────────────────────────────────┘
```### Non-cryptographic Hashers
```python
df = pl.DataFrame({
"foo":["hello_world"]
})result = df.select(plh.col('foo').nchash.wyhash())
print(result)
┌──────────────────────┐
│ foo │
│ --- │
│ u64 │
╞══════════════════════╡
│ 16737367591072095403 │
└──────────────────────┘```
### Geo Hashers
```python
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} ┆ 9q60y60rhs │
└─────────────────────┴────────────┘pl.select(pl.lit('9q60y60rhs').geohash.to_coords().alias('coordinates'))
shape: (1, 1)
┌───────────────────────┐
│ coordinates │
│ --- │
│ struct[2] │
╞═══════════════════════╡
│ {-120.6623,35.300298} │
└───────────────────────┘
```### H3 Spatial Index
```python
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 │
└─────────────────────┴─────────────────┘
```## Create hash from multiple columns
```python
df = pl.DataFrame({
"foo":["hello_world"],
"bar": ["today"]
})result = df.select(plh.concat_str('foo','bar').chash.sha256())
```