Sha256: 155ba5cbc48e336a8cc1caed2c32018aac65e56897798b7836edeaa9bd35f700

Contents?: true

Size: 1.23 KB

Versions: 47

Compression:

Stored size: 1.23 KB

Contents

module Polars
  # Series.struct namespace.
  class StructNameSpace
    include ExprDispatch

    self._accessor = "struct"

    # @private
    def initialize(series)
      self._s = series._s
    end

    # Retrieve one of the fields of this `Struct` as a new Series.
    #
    # @return [Series]
    def [](item)
      if item.is_a?(Integer)
        field(fields[item])
      elsif item.is_a?(String)
        field(item)
      else
        raise ArgumentError, "expected type Integer or String, got #{item.class.name}"
      end
    end

    # Convert this Struct Series to a DataFrame.
    #
    # @return [DataFrame]
    def to_frame
      Utils.wrap_df(_s.struct_to_frame)
    end

    # Get the names of the fields.
    #
    # @return [Array]
    def fields
      if _s.nil?
        []
      else
        _s.struct_fields
      end
    end

    # Retrieve one of the fields of this `Struct` as a new Series.
    #
    # @param name [String]
    #   Name of the field
    #
    # @return [Series]
    def field(name)
      super
    end

    # Rename the fields of the struct.
    #
    # @param names [Array]
    #   New names in the order of the struct's fields
    #
    # @return [Series]
    def rename_fields(names)
      super
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
polars-df-0.4.0-x86_64-linux lib/polars/struct_name_space.rb
polars-df-0.4.0-x86_64-darwin lib/polars/struct_name_space.rb
polars-df-0.4.0-arm64-darwin lib/polars/struct_name_space.rb
polars-df-0.4.0-aarch64-linux lib/polars/struct_name_space.rb
polars-df-0.4.0 lib/polars/struct_name_space.rb
polars-df-0.3.1-x86_64-linux lib/polars/struct_name_space.rb
polars-df-0.3.1-x86_64-darwin lib/polars/struct_name_space.rb
polars-df-0.3.1-arm64-darwin lib/polars/struct_name_space.rb
polars-df-0.3.1-aarch64-linux lib/polars/struct_name_space.rb
polars-df-0.3.1 lib/polars/struct_name_space.rb
polars-df-0.3.0-x86_64-linux lib/polars/struct_name_space.rb
polars-df-0.3.0-x86_64-darwin lib/polars/struct_name_space.rb
polars-df-0.3.0-arm64-darwin lib/polars/struct_name_space.rb
polars-df-0.3.0-aarch64-linux lib/polars/struct_name_space.rb
polars-df-0.3.0 lib/polars/struct_name_space.rb
polars-df-0.2.5-x86_64-linux lib/polars/struct_name_space.rb
polars-df-0.2.5-x86_64-darwin lib/polars/struct_name_space.rb
polars-df-0.2.5-arm64-darwin lib/polars/struct_name_space.rb
polars-df-0.2.5-aarch64-linux lib/polars/struct_name_space.rb
polars-df-0.2.5 lib/polars/struct_name_space.rb