Sha256: 8edc9363df2ba292d8199cac0a84fc5d468a54103cf09100805cb692585c187e

Contents?: true

Size: 1.24 KB

Versions: 27

Compression:

Stored size: 1.24 KB

Contents

module EasyML
  module Data
    module Splits
      class InMemorySplit < Split
        attr_accessor :dataset

        def initialize(options = {})
          @data = {}
          @dataset = options[:dataset]
        end

        # We don't backup in-memory splits to s3
        def download; end

        def upload; end

        def files
          []
        end

        def save(segment, df)
          @data[segment] = df
        end

        def read(segment, split_ys: false, target: nil, drop_cols: [], filter: nil, limit: nil, select: nil,
                          unique: nil)
          return nil if @data.keys.none?

          df = if segment.to_s == "all"
              Polars.concat(EasyML::Dataset::SPLIT_ORDER.map { |segment| @data[segment] }.compact)
            else
              @data[segment]
            end
          return nil if df.nil?

          df = df.filter(filter) if filter.present?
          drop_cols &= df.columns
          df = df.drop(drop_cols) unless drop_cols.empty?
          df = df.unique if unique

          split_features_targets(df, split_ys, target)
        end

        def cleanup
          @data.clear
        end

        def split_at
          @data.keys.empty? ? nil : Time.now
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
easy_ml-0.2.0.pre.rc27 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc26 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc25 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc24 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc23 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc22 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc21 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc20 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc19 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc18 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc17 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc16 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc15 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc14 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc13 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc12 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc11 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc10 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc9 lib/easy_ml/data/splits/in_memory_split.rb
easy_ml-0.2.0.pre.rc8 lib/easy_ml/data/splits/in_memory_split.rb