Skip to content

Commit

Permalink
Added enable_string_cache, disable_string_cache, and using_string_cac…
Browse files Browse the repository at this point in the history
…he to Polars
  • Loading branch information
ankane committed Mar 3, 2024
1 parent 1140602 commit b9e9a60
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ See the [upgrade guide](https://docs.pola.rs/releases/upgrade/0.20/)
- Added `Enum` type
- Added `Testing` module
- Added `arctan2`, `arctan2d`, `set_random_seed`, and `sql_expr` methods to `Polars`
- Added `enable_string_cache`, `disable_string_cache`, and `using_string_cache` to `Polars`
- Added methods for horizontal aggregations to `Polars`
- Added `sink_ipc`, `sink_csv`, and `sink_ndjson` methods to `LazyFrame`
- Added `replace` method to `Series` and `Expr`
Expand Down
1 change: 1 addition & 0 deletions lib/polars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
require_relative "polars/series"
require_relative "polars/slice"
require_relative "polars/sql_context"
require_relative "polars/string_cache"
require_relative "polars/string_expr"
require_relative "polars/string_name_space"
require_relative "polars/struct_expr"
Expand Down
68 changes: 68 additions & 0 deletions lib/polars/string_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module Polars
module Functions
# Enable the global string cache.
#
# `Categorical` columns created under the same global string cache have
# the same underlying physical value when string values are equal. This allows the
# columns to be concatenated or used in a join operation, for example.
#
# @return [nil]
#
# @example Construct two Series using the same global string cache.
# Polars.enable_string_cache
# s1 = Polars::Series.new("color", ["red", "green", "red"], dtype: Polars::Categorical)
# s2 = Polars::Series.new("color", ["blue", "red", "green"], dtype: Polars::Categorical)
# Polars.disable_string_cache
#
# @example 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"
# # ]
def enable_string_cache
Plr.enable_string_cache
end

# Disable and clear the global string cache.
#
# @return [nil]
#
# @example Construct two Series using the same global string cache.
# Polars.enable_string_cache
# s1 = Polars::Series.new("color", ["red", "green", "red"], dtype: Polars::Categorical)
# s2 = Polars::Series.new("color", ["blue", "red", "green"], dtype: Polars::Categorical)
# Polars.disable_string_cache
#
# @example 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"
# # ]
def disable_string_cache
Plr.disable_string_cache
end

# Check whether the global string cache is enabled.
#
# @return [Boolean]
def using_string_cache
Plr.using_string_cache
end
end
end

0 comments on commit b9e9a60

Please sign in to comment.