bytes — Byte encoding¶
Byte encoding, on pl.Expr as .bytes.
These expressions change a value into its own bytes, so you can send the
result to any hasher in nchash or
chash, or write it out directly. Each one accepts
Boolean, Int8/16/32/64, UInt8/16/32/64, Float32/64, Utf8 or Binary.
Each type keeps its own width: Int8 makes 1 byte, Int32 makes 4, Float64 makes 8, and so on. The two expressions differ only in the order of the bytes of that width. A value that is already bytes, Utf8 or Binary, has no byte order of its own, and it passes through unchanged either way.
Tip
This namespace encodes a value. It does not hash one. Send the result to a
hasher to get a hash of the value itself, and not of a string form of it:
plh.col("id").cast(pl.Int64).bytes.to_le().nchash.murmur32().
to_le
¶
Encode the value as its own bytes, least significant byte first.
Returns:
| Type | Description |
|---|---|
Expr
|
Binary, of the width of the input type. Boolean and the two 8-bit
integer types write one byte, Boolean as |
Raises:
| Type | Description |
|---|---|
ComputeError
|
The input is a type this namespace does not accept, for
example Date or Decimal. The message is |
Note
To get a different width, cast first.
plh.col("x").cast(pl.Int64).bytes.to_le() widens a narrower integer
to 8 bytes before it encodes, sign-extended as any polars numeric cast
is.
Examples:
to_be
¶
Encode the value as its own bytes, most significant byte first.
Everything on to_le() applies here,
except for the order of the bytes.
Returns:
| Type | Description |
|---|---|
Expr
|
Binary, of the width of the input type. |
Raises:
| Type | Description |
|---|---|
ComputeError
|
The input is a type this namespace does not accept. |
Examples: