polars bin2
An enhanced bin namespace for polars.
The polars str namespace contains many functions that would also be useful to have in the bin namespace. The polars_bin2 package implements these functions in the bin2 namespace for both Series and Expr in polars.
Most of the functions in polars_bin2 are currently implemented by 1) encoding binary data as str, 2) using the str namespace, and 3) converting the result approximately.
Example Usage
Importing polars_bin2 registers the namespace.
import polars_bin2
addresses = [
b'\xda\xc1\x7f\x95\x8d.\xe5#\xa2 b\x06\x99E\x97\xc1=\x83\x1e\xc7',
b'\xa0\xb8i\x91\xc6!\x8b6\xc1\xd1\x9dJ.\x9e\xb0\xce6\x06\xebH',
b'_\x98\x80ZN\x8b\xe2U\xa3(\x80\xfd\xec\x7fg(\xc6V\x8b\xa0'
]
series = pl.Series('address', addresses)
print(series.bin2.lengths())
Available functions in each namespace
(as of polars 0.18.13)
| function | str |
bin |
bin2 |
description |
|---|---|---|---|---|
concat |
✅ | ❌ | ✅ | concatenate series into single value |
contains |
✅ | ✅ | ✅ | check if value contains subvalue |
count_match |
✅ | ❌ | ✅ | count number of occurences |
decode |
✅ | ✅ | ✅ | decode using provided encoding |
encode |
✅ | ✅ | ✅ | encode using provided encoding |
ends_with |
✅ | ✅ | ✅ | check if value ends with subvalue |
lengths |
✅ | ❌ | ✅ | return byte length of each entry |
ljust |
✅ | ❌ | ✅ | left justify according to width |
replace |
✅ | ❌ | ✅ | replace first subvalue occurence with new value |
replace_all |
✅ | ❌ | ✅ | replace all subvalue occurences with new value |
rjust |
✅ | ❌ | ✅ | right justify according to width |
slice |
✅ | ❌ | ✅ | create subslices of each value |
split |
✅ | ❌ | ✅ | split each value by a subvalue |
starts_with |
✅ | ✅ | ✅ | check if value starts with subvalue |
zfill |
✅ | ❌ | ✅ | fill the value with zeros |
Strip functions cannot be implemented because strip works on single chars and bin-str encodings do not have a 1:1 mapping of bytes to chars. For example, using a hex encoding could remove an extra zero, making the encoding invalid, whereas base64 encoding does not have a 1:1 mapping of chars to bytes.
| function | str |
bin |
bin2 |
description |
|---|---|---|---|---|
lstrip |
✅ | ❌ | ❌ | remove leading subvalues |
rstrip |
✅ | ❌ | ❌ | remove trailing subvalues |
strip |
✅ | ❌ | ❌ | remove leading and trailing subvalues |
There are some other functions in the str namespace that are not applicable to binary data. These are not currently implemented in bin2, though there might be some reason to implement them in the future:
| function | str |
bin |
bin2 |
description |
|---|---|---|---|---|
explode |
✅ | ❌ | ❌ | return separate row for each subvalue |
extract |
✅ | ❌ | ❌ | extract target group from provided pattern |
extract_all |
✅ | ❌ | ❌ | extract all matches for provided pattern |
extract_groups |
✅ | ❌ | ❌ | extract all groups for provided pattern |
json_extract |
✅ | ❌ | ❌ | parse values as json |
json_path_match |
✅ | ❌ | ❌ | extract first match of JSON string |
n_chars |
✅ | ❌ | ❌ | return char length of each entry |
parse_int |
✅ | ❌ | ❌ | parse integers |
split_exact |
✅ | ❌ | ❌ | split each value by a subvalue using n splits |
splitn |
✅ | ❌ | ❌ | split each value by a subvalue at most n times |
strptime |
✅ | ❌ | ❌ | convert to a date/time column |
to_date |
✅ | ❌ | ❌ | convert to a date column |
to_datetime |
✅ | ❌ | ❌ | convert to a time column |
to_decimal |
✅ | ❌ | ❌ | convert to a decimal column |
to_lowercase |
✅ | ❌ | ❌ | convert to lowercase |
to_time |
✅ | ❌ | ❌ | convert to a time column |
to_titlecase |
✅ | ❌ | ❌ | convert to title case |
to_uppercase |
✅ | ❌ | ❌ | convert to upper case |
Metadata
Release files for polars_bin2 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| polars_bin2-0.1.0.tar.gz | 7.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| polars_bin2-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / polars_bin2-0.1.0.tar.gz
| Download URL | polars_bin2-0.1.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0f8d2408b0858c9e2d856b94504998ec88da753d1b118946c7713cf0de50cee
|
|
BLAKE2b-256 checksum How to use checksums |
436b14c0d3afff5a951d592d9d77abbc69933912fcde4a5eab47861dd252b7e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.30.0
|
Release files / polars_bin2-0.1.0-py3-none-any.whl
| Download URL | polars_bin2-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2c3df60abf53e48977d2544721e7bec434888a1a3692535d894917ed59393cd
|
|
BLAKE2b-256 checksum How to use checksums |
34fcd1f2e0bcec2a4090edb4eaf01b2f15852d3466e948568a3c0ab400efe3d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.30.0
|
Security for polars_bin2 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.