polars.Expr.bin.decode#

Expr.bin.decode(encoding: TransferEncoding, *, strict: bool = True) Expr[source]#

Decode values using the provided encoding.

Parameters:
encoding{‘hex’, ‘base64’}

The encoding to use.

strict

Raise an error if the underlying value cannot be decoded, otherwise mask out with a null value.

Returns:
Expr

Expression of data type String.

Examples

>>> colors = pl.DataFrame(
...     {
...         "name": ["black", "yellow", "blue"],
...         "code": [b"\x00\x00\x00", b"\xff\xff\x00", b"\x00\x00\xff"],
...     }
... )
>>> colors.with_columns(
...     pl.col("code").bin.encode("hex").alias("encoded"),
... )
shape: (3, 3)
┌────────┬─────────────────┬─────────┐
│ name   ┆ code            ┆ encoded │
│ ---    ┆ ---             ┆ ---     │
│ str    ┆ binary          ┆ str     │
╞════════╪═════════════════╪═════════╡
│ black  ┆ b"\x00\x00\x00" ┆ 000000  │
│ yellow ┆ b"\xff\xff\x00" ┆ ffff00  │
│ blue   ┆ b"\x00\x00\xff" ┆ 0000ff  │
└────────┴─────────────────┴─────────┘