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