Class: Polars::BinaryNameSpace

Inherits:
Object
  • Object
show all
Defined in:
lib/polars/binary_name_space.rb

Overview

Series.bin namespace.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Polars::ExprDispatch

Instance Method Details

#contains(literal) ⇒ Series

Check if binaries in Series contain a binary substring.

Examples:

s = Polars::Series.new("colors", ["\x00\x00\x00".b, "\xff\xff\x00".b, "\x00\x00\xff".b])
s.bin.contains("\xff".b)
# =>
# shape: (3,)
# Series: 'colors' [bool]
# [
#         false
#         true
#         true
# ]

Parameters:

  • literal (String)

    The binary substring to look for

Returns:



31
32
33
# File 'lib/polars/binary_name_space.rb', line 31

def contains(literal)
  super
end

#decode(encoding, strict: true) ⇒ Series

Decode a value using the provided encoding.

Examples:

Decode values using hexadecimal encoding.

s = Polars::Series.new("colors", ["000000".b, "ffff00".b, "0000ff".b])
s.bin.decode("hex")
# =>
# shape: (3,)
# Series: 'colors' [binary]
# [
#         b"\x00\x00\x00"
#         b"\xff\xff\x00"
#         b"\x00\x00\xff"
# ]

Decode values using Base64 encoding.

s = Polars::Series.new("colors", ["AAAA".b, "//8A".b, "AAD/".b])
s.bin.decode("base64")
# =>
# shape: (3,)
# Series: 'colors' [binary]
# [
#         b"\x00\x00\x00"
#         b"\xff\xff\x00"
#         b"\x00\x00\xff"
# ]

Set strict=False to set invalid values to null instead of raising an error.

s = Polars::Series.new("colors", ["000000".b, "ffff00".b, "invalid_value".b])
s.bin.decode("hex", strict: false)
# =>
# shape: (3,)
# Series: 'colors' [binary]
# [
#         b"\x00\x00\x00"
#         b"\xff\xff\x00"
#         null
# ]

Parameters:

  • encoding ("hex", "base64")

    The encoding to use.

  • strict (Boolean) (defaults to: true)

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

Returns:



124
125
126
# File 'lib/polars/binary_name_space.rb', line 124

def decode(encoding, strict: true)
  super
end

#encode(encoding) ⇒ Series

Encode a value using the provided encoding.

Examples:

Encode values using hexadecimal encoding.

s = Polars::Series.new("colors", ["\x00\x00\x00".b, "\xff\xff\x00".b, "\x00\x00\xff".b])
s.bin.encode("hex")
# =>
# shape: (3,)
# Series: 'colors' [str]
# [
#         "000000"
#         "ffff00"
#         "0000ff"
# ]

Encode values using Base64 encoding.

s.bin.encode("base64")
# =>
# shape: (3,)
# Series: 'colors' [str]
# [
#         "AAAA"
#         "//8A"
#         "AAD/"
# ]

Parameters:

  • encoding ("hex", "base64")

    The encoding to use.

Returns:



157
158
159
# File 'lib/polars/binary_name_space.rb', line 157

def encode(encoding)
  super
end

#ends_with(suffix) ⇒ Series

Check if string values end with a binary substring.

Examples:

s = Polars::Series.new("colors", ["\x00\x00\x00".b, "\xff\xff\x00".b, "\x00\x00\xff".b])
s.bin.ends_with("\x00".b)
# =>
# shape: (3,)
# Series: 'colors' [bool]
# [
#         true
#         true
#         false
# ]

Parameters:

  • suffix (String)

    Suffix substring.

Returns:



53
54
55
# File 'lib/polars/binary_name_space.rb', line 53

def ends_with(suffix)
  super
end

#starts_with(prefix) ⇒ Series

Check if values start with a binary substring.

Examples:

s = Polars::Series.new("colors", ["\x00\x00\x00".b, "\xff\xff\x00".b, "\x00\x00\xff".b])
s.bin.starts_with("\x00".b)
# =>
# shape: (3,)
# Series: 'colors' [bool]
# [
#         true
#         false
#         true
# ]

Parameters:

  • prefix (String)

    Prefix substring.

Returns:



75
76
77
# File 'lib/polars/binary_name_space.rb', line 75

def starts_with(prefix)
  super
end