Sha256: 2df95fe6f9b72a4c87f9c2c864a0a79dde8dce4b2007e338ab0d6452d076614e

Contents?: true

Size: 962 Bytes

Versions: 1

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

module RedAmber
  # mix-ins for the class DataFrame
  module DataFrameLoadSave
    # Enable `self.load` as class method of DataFrame
    def self.included(klass)
      klass.extend ClassMethods
    end

    # Enable `self.load` as class method of DataFrame
    module ClassMethods
      # Load DataFrame via Arrow::Table.load
      def load(path, options = {})
        DataFrame.new(Arrow::Table.load(path, options))
      end
    end

    # Save DataFrame
    #
    # @return [DataFrame] self.
    def save(output, options = {})
      @table.save(output, options)
      self
    end

    # Save and reload to cast automatically
    #   Via tsv format file temporally as default
    #
    # @note experimental feature
    def auto_cast(format: :tsv)
      return self if empty?

      tempfile = Arrow::ResizableBuffer.new(1024)
      save(tempfile, format: format)
      DataFrame.load(tempfile, format: format)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
red_amber-0.3.0 lib/red_amber/data_frame_loadsave.rb