Module: Daru::Core::Query

Defined in:
lib/daru/core/query.rb

Defined Under Namespace

Classes: BoolArray

Class Method Summary collapse

Class Method Details

.apply_scalar_operator(operator, data, other) ⇒ Object



41
42
43
# File 'lib/daru/core/query.rb', line 41

def apply_scalar_operator operator, data, other
  BoolArray.new data.map { |d| !!d.send(operator, other) }
end

.apply_vector_operator(operator, vector, other) ⇒ Object



45
46
47
# File 'lib/daru/core/query.rb', line 45

def apply_vector_operator operator, vector, other
  BoolArray.new vector.zip(other).map { |d, o| !!d.send(operator, o) }
end

.df_where(data_frame, bool_array) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/daru/core/query.rb', line 49

def df_where data_frame, bool_array
  vecs = data_frame.map do |vector|
    vector.where(bool_array)
  end

  Daru::DataFrame.new(
    vecs, order: data_frame.vectors, index: vecs[0].index, clone: false
  )
end

.vector_where(data, index, bool_array, dtype) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/daru/core/query.rb', line 59

def vector_where data, index, bool_array, dtype
  new_data = []
  new_index = []
  bool_array.to_a.each_with_index do |b, i|
    if b
      new_data << data[i]
      new_index << index[i]
    end
  end

  Daru::Vector.new(new_data, index: new_index, dtype: dtype)
end