Class: Polars::BinaryExpr
- Inherits:
-
Object
- Object
- Polars::BinaryExpr
- Defined in:
- lib/polars/binary_expr.rb
Overview
Namespace for binary related expressions.
Instance Method Summary collapse
-
#contains(literal) ⇒ Expr
Check if binaries in Series contain a binary substring.
-
#decode(encoding, strict: true) ⇒ Expr
Decode a value using the provided encoding.
-
#encode(encoding) ⇒ Expr
Encode a value using the provided encoding.
-
#ends_with(suffix) ⇒ Expr
Check if string values end with a binary substring.
-
#get(index, null_on_oob: false) ⇒ Expr
Get the byte value at the given index.
-
#head(n = 5) ⇒ Expr
Take the first
nbytes of the binary values. -
#reinterpret(dtype:, endianness: "little") ⇒ Expr
Interpret a buffer as a numerical Polars type.
-
#size(unit = "b") ⇒ Expr
Get the size of binary values in the given unit.
-
#slice(offset, length = nil) ⇒ Expr
Slice the binary values.
-
#starts_with(prefix) ⇒ Expr
Check if values start with a binary substring.
-
#tail(n = 5) ⇒ Expr
Take the last
nbytes of the binary values.
Instance Method Details
#contains(literal) ⇒ Expr
Check if binaries in Series contain a binary substring.
43 44 45 46 |
# File 'lib/polars/binary_expr.rb', line 43 def contains(literal) literal = Utils.parse_into_expression(literal, str_as_lit: true) Utils.wrap_expr(_rbexpr.binary_contains(literal)) end |
#decode(encoding, strict: true) ⇒ Expr
Decode a value using the provided encoding.
153 154 155 156 157 158 159 160 161 |
# File 'lib/polars/binary_expr.rb', line 153 def decode(encoding, strict: true) if encoding == "hex" Utils.wrap_expr(_rbexpr.binary_hex_decode(strict)) elsif encoding == "base64" Utils.wrap_expr(_rbexpr.binary_base64_decode(strict)) else raise ArgumentError, "encoding must be one of {{'hex', 'base64'}}, got #{encoding}" end end |
#encode(encoding) ⇒ Expr
Encode a value using the provided encoding.
191 192 193 194 195 196 197 198 199 |
# File 'lib/polars/binary_expr.rb', line 191 def encode(encoding) if encoding == "hex" Utils.wrap_expr(_rbexpr.binary_hex_encode) elsif encoding == "base64" Utils.wrap_expr(_rbexpr.binary_base64_encode) else raise ArgumentError, "encoding must be one of {{'hex', 'base64'}}, got #{encoding}" end end |
#ends_with(suffix) ⇒ Expr
Check if string values end with a binary substring.
79 80 81 82 |
# File 'lib/polars/binary_expr.rb', line 79 def ends_with(suffix) suffix = Utils.parse_into_expression(suffix, str_as_lit: true) Utils.wrap_expr(_rbexpr.binary_ends_with(suffix)) end |
#get(index, null_on_oob: false) ⇒ Expr
Get the byte value at the given index.
For example, index 0 would return the first byte of every binary value
and index -1 would return the last byte of every binary value.
If an index is out of bounds, it will return a None.
413 414 415 416 |
# File 'lib/polars/binary_expr.rb', line 413 def get(index, null_on_oob: false) index_rbexpr = Utils.parse_into_expression(index) Utils.wrap_expr(_rbexpr.bin_get(index_rbexpr, null_on_oob)) end |
#head(n = 5) ⇒ Expr
(1) A similar method exists for taking the last n bytes: :func:tail.
(2) If n is negative, it is interpreted as "until the nth byte from the end",
e.g., head(-3) returns all but the last three bytes.
Take the first n bytes of the binary values.
339 340 341 342 |
# File 'lib/polars/binary_expr.rb', line 339 def head(n = 5) n_rbexpr = Utils.parse_into_expression(n, str_as_lit: false) Utils.wrap_expr(_rbexpr.bin_head(n_rbexpr)) end |
#reinterpret(dtype:, endianness: "little") ⇒ Expr
Interpret a buffer as a numerical Polars type.
257 258 259 260 261 262 263 264 265 266 |
# File 'lib/polars/binary_expr.rb', line 257 def reinterpret( dtype:, endianness: "little" ) dtype = Utils.parse_into_datatype_expr(dtype) Utils.wrap_expr( _rbexpr.bin_reinterpret(dtype._rbdatatype_expr, endianness) ) end |
#size(unit = "b") ⇒ Expr
Get the size of binary values in the given unit.
225 226 227 228 229 |
# File 'lib/polars/binary_expr.rb', line 225 def size(unit = "b") sz = Utils.wrap_expr(_rbexpr.bin_size_bytes) sz = Utils.scale_bytes(sz, to: unit) sz end |
#slice(offset, length = nil) ⇒ Expr
Slice the binary values.
299 300 301 302 303 |
# File 'lib/polars/binary_expr.rb', line 299 def slice(offset, length = nil) offset_rbexpr = Utils.parse_into_expression(offset) length_rbexpr = Utils.parse_into_expression(length) Utils.wrap_expr(_rbexpr.bin_slice(offset_rbexpr, length_rbexpr)) end |
#starts_with(prefix) ⇒ Expr
Check if values start with a binary substring.
117 118 119 120 |
# File 'lib/polars/binary_expr.rb', line 117 def starts_with(prefix) prefix = Utils.parse_into_expression(prefix, str_as_lit: true) Utils.wrap_expr(_rbexpr.binary_starts_with(prefix)) end |
#tail(n = 5) ⇒ Expr
(1) A similar method exists for taking the first n bytes: head.
(2) If n is negative, it is interpreted as "starting at the nth byte",
e.g., tail(-3) returns all but the first three bytes.
Take the last n bytes of the binary values.
378 379 380 381 |
# File 'lib/polars/binary_expr.rb', line 378 def tail(n = 5) n_rbexpr = Utils.parse_into_expression(n, str_as_lit: false) Utils.wrap_expr(_rbexpr.bin_tail(n_rbexpr)) end |