Skip to content

Check if binaries contain a binary substring

Source code

Description

Check if binaries contain a binary substring

Usage

<Expr>$bin$contains(literal)

Arguments

literal The binary substring to look for.

Value

Expr returning a Boolean

Examples

library("polars")

colors = pl$DataFrame(
  name = c("black", "yellow", "blue"),
  code = as_polars_series(c("x00x00x00", "xffxffx00", "x00x00xff"))$cast(pl$Binary),
  lit = as_polars_series(c("x00", "xffx00", "xffxff"))$cast(pl$Binary)
)

colors$select(
  "name",
  contains_with_lit = pl$col("code")$bin$contains("xff"),
  contains_with_expr = pl$col("code")$bin$contains(pl$col("lit"))
)
#> shape: (3, 3)
#> ┌────────┬───────────────────┬────────────────────┐
#> │ name   ┆ contains_with_lit ┆ contains_with_expr │
#> │ ---    ┆ ---               ┆ ---                │
#> │ str    ┆ bool              ┆ bool               │
#> ╞════════╪═══════════════════╪════════════════════╡
#> │ black  ┆ false             ┆ true               │
#> │ yellow ┆ true              ┆ true               │
#> │ blue   ┆ true              ┆ false              │
#> └────────┴───────────────────┴────────────────────┘