Class: Daru::Core::MergeFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/daru/core/merge.rb

Defined Under Namespace

Classes: NilSorter

Instance Method Summary collapse

Constructor Details

#initialize(left_df, right_df, opts = {}) ⇒ MergeFrame

rubocop:disable Metrics/AbcSize – quick-fix for issue #171



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/daru/core/merge.rb', line 20

def initialize left_df, right_df, opts={} # rubocop:disable Metrics/AbcSize -- quick-fix for issue #171
  init_opts(opts)
  validate_on!(left_df, right_df)
  key_sanitizer = ->(h) { sanitize_merge_keys(h.values_at(*on)) }

  @left = df_to_a(left_df)
  @left.sort! { |a, b| safe_compare(a.values_at(*on), b.values_at(*on)) }
  @left_key_values = @left.map(&key_sanitizer)

  @right = df_to_a(right_df)
  @right.sort! { |a, b| safe_compare(a.values_at(*on), b.values_at(*on)) }
  @right_key_values = @right.map(&key_sanitizer)

  @left_keys, @right_keys = merge_keys(left_df, right_df, on)
end

Instance Method Details

#joinObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/daru/core/merge.rb', line 36

def join
  res = []

  until left.empty? && right.empty?
    lkey = first_left_key
    rkey = first_right_key

    row(lkey, rkey).tap { |r| res << r if r }
  end

  Daru::DataFrame.new(res, order: dataframe_vector_names)
end