Sha256: 792fb629c3b508d259f58778ed193bcb0e1ec551e418eff44db2ca378a1262b4

Contents?: true

Size: 1.6 KB

Versions: 33

Compression:

Stored size: 1.6 KB

Contents

module Polars
  # Namespace for categorical related expressions.
  class CatExpr
    # @private
    attr_accessor :_rbexpr

    # @private
    def initialize(expr)
      self._rbexpr = expr._rbexpr
    end

    # Determine how this categorical series should be sorted.
    #
    # @param ordering ["physical", "lexical"]
    #   Ordering type:
    #
    #   - 'physical' -> Use the physical representation of the categories to determine the order (default).
    #   - 'lexical' -> Use the string values to determine the ordering.
    #
    # @return [Expr]
    #
    # @example
    #   df = Polars::DataFrame.new(
    #     {"cats" => ["z", "z", "k", "a", "b"], "vals" => [3, 1, 2, 2, 3]}
    #   ).with_columns(
    #     [
    #       Polars.col("cats").cast(:cat).cat.set_ordering("lexical")
    #     ]
    #   )
    #   df.sort(["cats", "vals"])
    #   # =>
    #   # shape: (5, 2)
    #   # ┌──────┬──────┐
    #   # │ cats ┆ vals │
    #   # │ ---  ┆ ---  │
    #   # │ cat  ┆ i64  │
    #   # ╞══════╪══════╡
    #   # │ a    ┆ 2    │
    #   # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
    #   # │ b    ┆ 3    │
    #   # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
    #   # │ k    ┆ 2    │
    #   # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
    #   # │ z    ┆ 1    │
    #   # ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
    #   # │ z    ┆ 3    │
    #   # └──────┴──────┘
    def set_ordering(ordering)
      Utils.wrap_expr(_rbexpr.cat_set_ordering(ordering))
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
polars-df-0.2.1-x86_64-linux lib/polars/cat_expr.rb
polars-df-0.2.1-x86_64-darwin lib/polars/cat_expr.rb
polars-df-0.2.1-arm64-darwin lib/polars/cat_expr.rb
polars-df-0.2.1-aarch64-linux lib/polars/cat_expr.rb
polars-df-0.2.1 lib/polars/cat_expr.rb
polars-df-0.2.0-x86_64-linux lib/polars/cat_expr.rb
polars-df-0.2.0-x86_64-darwin lib/polars/cat_expr.rb
polars-df-0.2.0-arm64-darwin lib/polars/cat_expr.rb
polars-df-0.2.0-aarch64-linux lib/polars/cat_expr.rb
polars-df-0.2.0 lib/polars/cat_expr.rb
polars-df-0.1.5 lib/polars/cat_expr.rb
polars-df-0.1.4 lib/polars/cat_expr.rb
polars-df-0.1.3 lib/polars/cat_expr.rb