Skip to content

Check if string values end with a binary substring

Source code

Description

Check if string values end with a binary substring

Usage

<Expr>$bin$ends_with(suffix)

Arguments

suffix Suffix substring.

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),
  suffix = as_polars_series(c("x00", "xffx00", "xffxff"))$cast(pl$Binary)
)

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