Class: EasyML::Data::Datasource::PolarsDatasource

Inherits:
EasyML::Data::Datasource show all
Includes:
GlueGun::DSL
Defined in:
lib/easy_ml/data/datasource/polars_datasource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PolarsDatasource

Returns a new instance of PolarsDatasource.



15
16
17
18
# File 'lib/easy_ml/data/datasource/polars_datasource.rb', line 15

def initialize(options)
  super
  @last_updated_at = Time.now
end

Instance Attribute Details

#last_updated_atObject

Returns the value of attribute last_updated_at.



13
14
15
# File 'lib/easy_ml/data/datasource/polars_datasource.rb', line 13

def last_updated_at
  @last_updated_at
end

Instance Method Details

#dataObject



36
37
38
# File 'lib/easy_ml/data/datasource/polars_datasource.rb', line 36

def data
  df
end

#df_is_dataframeObject



8
9
10
11
12
# File 'lib/easy_ml/data/datasource/polars_datasource.rb', line 8

def df_is_dataframe
  return if df.nil? || df.is_a?(Polars::DataFrame)

  errors.add(:df, "Must be an instance of Polars::DataFrame")
end

#filesObject



28
29
30
# File 'lib/easy_ml/data/datasource/polars_datasource.rb', line 28

def files
  [] # No files, as this is in-memory
end

#in_batches(of: 10_000) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/easy_ml/data/datasource/polars_datasource.rb', line 20

def in_batches(of: 10_000)
  total_rows = df.shape[0]
  (0...total_rows).step(of) do |start|
    end_index = [start + of, total_rows].min
    yield df.slice(start, end_index - start)
  end
end

#refresh!Object



32
33
34
# File 'lib/easy_ml/data/datasource/polars_datasource.rb', line 32

def refresh!
  # No need to refresh for in-memory datasource
end