Class: Polars::StringCache

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

Overview

Class for enabling and disabling the global string cache.

Examples:

Construct two Series using the same global string cache.

s1 = nil
s2 = nil
Polars::StringCache.new do
  s1 = Polars::Series.new("color", ["red", "green", "red"], dtype: Polars::Categorical)
  s2 = Polars::Series.new("color", ["blue", "red", "green"], dtype: Polars::Categorical)
end

As both Series are constructed under the same global string cache, they can be concatenated.

Polars.concat([s1, s2])
# =>
# shape: (6,)
# Series: 'color' [cat]
# [
#         "red"
#         "green"
#         "red"
#         "blue"
#         "red"
#         "green"
# ]

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ StringCache

Returns a new instance of StringCache.



26
27
28
# File 'lib/polars/string_cache.rb', line 26

def initialize(&block)
  RbStringCacheHolder.hold(&block)
end