Class: Polars::CatNameSpace

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

Overview

Series.cat 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

#ends_with(suffix) ⇒ Series

Check if string representations of values end with a substring.

Examples:

s = Polars::Series.new("fruits", ["apple", "mango", nil], dtype: Polars::Categorical)
s.cat.ends_with("go")
# =>
# shape: (3,)
# Series: 'fruits' [bool]
# [
#         false
#         true
#         null
# ]

Parameters:

  • suffix (String)

    Suffix substring.

Returns:



144
145
146
# File 'lib/polars/cat_name_space.rb', line 144

def ends_with(suffix)
  super
end

#get_categoriesSeries

Get the categories stored in this data type.

Examples:

s = Polars::Series.new(["foo", "bar", "foo", "foo", "ham"], dtype: Polars::Categorical)
s.cat.get_categories
# =>
# shape: (3,)
# Series: '' [str]
# [
#         "foo"
#         "bar"
#         "ham"
# ]

Returns:



28
29
30
# File 'lib/polars/cat_name_space.rb', line 28

def get_categories
  super
end

#is_localBoolean

Return whether or not the column is a local categorical.

Always returns false.

Returns:



37
38
39
# File 'lib/polars/cat_name_space.rb', line 37

def is_local
  _s.cat_is_local
end

#len_bytesSeries

Return the byte-length of the string representation of each value.

Examples:

s = Polars::Series.new(["Café", "345", "東京", nil], dtype: Polars::Categorical)
s.cat.len_bytes
# =>
# shape: (4,)
# Series: '' [u32]
# [
#         5
#         3
#         6
#         null
# ]

Returns:



80
81
82
# File 'lib/polars/cat_name_space.rb', line 80

def len_bytes
  super
end

#len_charsSeries

Return the number of characters of the string representation of each value.

Examples:

s = Polars::Series.new(["Café", "345", "東京", nil], dtype: Polars::Categorical)
s.cat.len_chars
# =>
# shape: (4,)
# Series: '' [u32]
# [
#         4
#         3
#         2
#         null
# ]

Returns:



100
101
102
# File 'lib/polars/cat_name_space.rb', line 100

def len_chars
  super
end

#slice(offset, length = nil) ⇒ Series

Extract a substring from the string representation of each string value.

Examples:

s = Polars::Series.new(["pear", nil, "papaya", "dragonfruit"], dtype: Polars::Categorical)
s.cat.slice(-3)
# =>
# shape: (4,)
# Series: '' [str]
# [
#         "ear"
#         null
#         "aya"
#         "uit"
# ]

Using the optional length parameter

s.cat.slice(4, 3)
# =>
# shape: (4,)
# Series: '' [str]
# [
#         ""
#         null
#         "ya"
#         "onf"
# ]

Parameters:

  • offset (Integer)

    Start index. Negative indexing is supported.

  • length (Integer) (defaults to: nil)

    Length of the slice. If set to nil (default), the slice is taken to the end of the string.

Returns:



182
183
184
# File 'lib/polars/cat_name_space.rb', line 182

def slice(offset, length = nil)
  super
end

#starts_with(prefix) ⇒ Series

Check if string representations of values start with a substring.

Examples:

s = Polars::Series.new("fruits", ["apple", "mango", nil], dtype: Polars::Categorical)
s.cat.starts_with("app")
# =>
# shape: (3,)
# Series: 'fruits' [bool]
# [
#         true
#         false
#         null
# ]

Parameters:

  • prefix (String)

    Prefix substring.

Returns:



122
123
124
# File 'lib/polars/cat_name_space.rb', line 122

def starts_with(prefix)
  super
end

#to_localSeries

Simply returns the column as-is, local representations are deprecated.

Returns:



44
45
46
# File 'lib/polars/cat_name_space.rb', line 44

def to_local
  Utils.wrap_s(_s.cat_to_local)
end

#uses_lexical_orderingBoolean

Note:

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Indicate whether the Series uses lexical ordering.

Examples:

s = Polars::Series.new(["b", "a", "b"]).cast(Polars::Categorical)
s.cat.uses_lexical_ordering
# => true

Returns:



60
61
62
# File 'lib/polars/cat_name_space.rb', line 60

def uses_lexical_ordering
  _s.cat_uses_lexical_ordering
end