red_amber 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +39 -20
  3. data/.yardopts +2 -0
  4. data/CHANGELOG.md +113 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE +1 -1
  7. data/README.md +25 -26
  8. data/benchmark/basic.yml +2 -2
  9. data/benchmark/combine.yml +2 -2
  10. data/benchmark/dataframe.yml +2 -2
  11. data/benchmark/group.yml +2 -2
  12. data/benchmark/reshape.yml +2 -2
  13. data/benchmark/vector.yml +3 -0
  14. data/doc/DataFrame.md +32 -12
  15. data/doc/DataFrame_Comparison.md +65 -0
  16. data/doc/SubFrames.md +11 -0
  17. data/doc/Vector.md +207 -1
  18. data/doc/yard-templates/default/fulldoc/html/css/common.css +6 -0
  19. data/lib/red_amber/data_frame.rb +429 -75
  20. data/lib/red_amber/data_frame_combinable.rb +516 -66
  21. data/lib/red_amber/data_frame_displayable.rb +244 -14
  22. data/lib/red_amber/data_frame_indexable.rb +121 -18
  23. data/lib/red_amber/data_frame_loadsave.rb +78 -10
  24. data/lib/red_amber/data_frame_reshaping.rb +184 -14
  25. data/lib/red_amber/data_frame_selectable.rb +622 -66
  26. data/lib/red_amber/data_frame_variable_operation.rb +446 -34
  27. data/lib/red_amber/group.rb +187 -22
  28. data/lib/red_amber/helper.rb +70 -10
  29. data/lib/red_amber/refinements.rb +12 -5
  30. data/lib/red_amber/subframes.rb +1066 -0
  31. data/lib/red_amber/vector.rb +385 -11
  32. data/lib/red_amber/vector_aggregation.rb +312 -0
  33. data/lib/red_amber/vector_binary_element_wise.rb +387 -0
  34. data/lib/red_amber/vector_selectable.rb +217 -12
  35. data/lib/red_amber/vector_unary_element_wise.rb +436 -0
  36. data/lib/red_amber/vector_updatable.rb +278 -34
  37. data/lib/red_amber/version.rb +2 -1
  38. data/lib/red_amber.rb +13 -1
  39. data/red_amber.gemspec +2 -2
  40. metadata +13 -8
  41. data/doc/image/dataframe/reshaping_DataFrames.png +0 -0
  42. data/lib/red_amber/vector_functions.rb +0 -242
@@ -1,39 +1,118 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedAmber
4
- # mix-ins for the class DataFrame
4
+ # Mix-in for the class DataFrame
5
5
  module DataFrameVariableOperation
6
6
  # Array is refined
7
7
  using RefineArray
8
8
 
9
- # Pick up variables (columns) to create a new DataFrame
9
+ # Select variables (columns) to create a new DataFrame.
10
10
  #
11
- # @note DataFrame#pick creates a DataFrame with single key.
12
- # DataFrame#[] creates a Vector if single key is specified.
11
+ # @note if a single key is specified, DataFrame#pick generates a DataFrame.
12
+ # On the other hand, DataFrame#[] generates a Vector.
13
13
  #
14
14
  # @overload pick(keys)
15
- # Pick variables by Symbols or Strings.
15
+ # Pick up variables by Symbol(s) or String(s).
16
16
  #
17
17
  # @param keys [Symbol, String, <Symbol, String>]
18
18
  # key name(s) of variables to pick.
19
19
  # @return [DataFrame]
20
- # Picked DataFrame.
20
+ # picked DataFrame.
21
+ # @example Pick up by a key
22
+ # languages
23
+ #
24
+ # # =>
25
+ # #<RedAmber::DataFrame : 4 x 3 Vectors, 0x00000000000cfd8c>
26
+ # Language Creator Released
27
+ # <string> <string> <uint16>
28
+ # 0 Ruby Yukihiro Matsumoto 1995
29
+ # 1 Python Guido van Rossum 1991
30
+ # 2 R Ross Ihaka and Robert Gentleman 1993
31
+ # 3 Rust Graydon Hoare 2001
32
+ #
33
+ # languages.pick(:Language)
34
+ #
35
+ # # =>
36
+ # #<RedAmber::DataFrame : 4 x 1 Vector, 0x0000000000113d20>
37
+ # Language
38
+ # <string>
39
+ # 0 Ruby
40
+ # 1 Python
41
+ # 2 R
42
+ # 3 Rust
43
+ #
44
+ # languages[:Language]
45
+ #
46
+ # # =>
47
+ # #<RedAmber::Vector(:string, size=4):0x000000000010359c>
48
+ # ["Ruby", "Python", "R", "Rust"]
21
49
  #
22
50
  # @overload pick(booleans)
23
- # Pick variables by booleans.
51
+ # Pick up variables by booleans.
24
52
  #
25
- # @param booleans [<true, false, nil>]
26
- # boolean array to pick variables at true.
53
+ # @param booleans [<Booleans, nil>, Vector]
54
+ # boolean array or vecctor to pick up variables at true.
27
55
  # @return [DataFrame]
28
- # Picked DataFrame.
56
+ # picked DataFrame.
57
+ # @example Pick up by booleans
58
+ # languages.pick(true, true, false)
59
+ #
60
+ # # =>
61
+ # #<RedAmber::DataFrame : 4 x 2 Vectors, 0x0000000000066a1c>
62
+ # Language Creator
63
+ # <string> <string>
64
+ # 0 Ruby Yukihiro Matsumoto
65
+ # 1 Python Guido van Rossum
66
+ # 2 R Ross Ihaka and Robert Gentleman
67
+ # 3 Rust Graydon Hoare
68
+ #
69
+ # is_string = languages.vectors.map(&:string?) # [true, true, false]
70
+ # languages.pick(is_string)
71
+ # # =>
72
+ # (same as above)
29
73
  #
30
74
  # @overload pick(indices)
31
- # Pick variables by column indices.
75
+ # Pick up variables by column indices.
32
76
  #
33
77
  # @param indices [Integer, Float, Range<Integer>, Vector, Arrow::Array]
34
- # numeric array to pick variables by column index.
78
+ # numeric array to pick up variables by column index.
79
+ # @return [DataFrame]
80
+ # picked DataFrame.
81
+ # @example Pick up by indices
82
+ # languages.pick(0, 2, 1)
83
+ #
84
+ # # =>
85
+ # #<RedAmber::DataFrame : 4 x 3 Vectors, 0x000000000011cfb0>
86
+ # Language Released Creator
87
+ # <string> <uint16> <string>
88
+ # 0 Ruby 1995 Yukihiro Matsumoto
89
+ # 1 Python 1991 Guido van Rossum
90
+ # 2 R 1993 Ross Ihaka and Robert Gentleman
91
+ # 3 Rust 2001 Graydon Hoare
92
+ #
93
+ # @overload pick
94
+ # Pick up variables by the yielded value from the block.
95
+ # @note Arguments and a block cannot be used simultaneously.
96
+ #
97
+ # @yield [self]
98
+ # the block is called within the context of self.
99
+ # (Block is called by instance_eval(&block). )
100
+ # @yieldreturn [keys, booleans, indices]
101
+ # returns keys, booleans or indices just same as arguments.
35
102
  # @return [DataFrame]
36
- # Picked DataFrame.
103
+ # picked DataFrame.
104
+ # @example Pick up by a block.
105
+ # # same as languages.pick { |df| df.languages.vectors.map(&:string?) }
106
+ # languages.pick { languages.vectors.map(&:string?) }
107
+ #
108
+ # # =>
109
+ # #<RedAmber::DataFrame : 4 x 2 Vectors, 0x0000000000154104>
110
+ # Language Creator
111
+ # <string> <string>
112
+ # 0 Ruby Yukihiro Matsumoto
113
+ # 1 Python Guido van Rossum
114
+ # 2 R Ross Ihaka and Robert Gentleman
115
+ # 3 Rust Graydon Hoare
37
116
  #
38
117
  def pick(*args, &block)
39
118
  if block
@@ -47,9 +126,9 @@ module RedAmber
47
126
  case args
48
127
  in [] | [nil]
49
128
  return DataFrame.new
50
- in [*] if args.symbols?
129
+ in [*] if args.symbol?
51
130
  return DataFrame.create(@table.select_columns(*args))
52
- in [*] if args.booleans?
131
+ in [*] if args.boolean?
53
132
  picker = keys.select_by_booleans(args)
54
133
  return DataFrame.create(@table.select_columns(*picker))
55
134
  in [(Vector | Arrow::Array | Arrow::ChunkedArray) => a]
@@ -60,7 +139,7 @@ module RedAmber
60
139
 
61
140
  return DataFrame.new if picker.compact.empty?
62
141
 
63
- if picker.booleans?
142
+ if picker.boolean?
64
143
  picker = keys.select_by_booleans(picker)
65
144
  return DataFrame.create(@table.select_columns(*picker))
66
145
  end
@@ -70,33 +149,102 @@ module RedAmber
70
149
  DataFrame.create(@table.select_columns(*picker))
71
150
  end
72
151
 
73
- # Drop some variables (columns) to create a remainer DataFrame
152
+ # Drop off some variables (columns) to create a remainer DataFrame.
74
153
  #
75
- # @note DataFrame#drop creates a DataFrame even if it is a single column.
154
+ # @note DataFrame#drop creates a DataFrame even if it is a single column
155
+ # (not a Vector).
76
156
  #
77
157
  # @overload drop(keys)
78
- # Drop variables by Symbols or Strings.
158
+ # Drop off variables by Symbol(s) or String(s).
79
159
  #
80
160
  # @param keys [Symbol, String, <Symbol, String>]
81
161
  # key name(s) of variables to drop.
82
162
  # @return [DataFrame]
83
- # Remainer DataFrame.
163
+ # remainer DataFrame.
164
+ # @example Drop off by a key
165
+ # languages
166
+ #
167
+ # # =>
168
+ # #<RedAmber::DataFrame : 4 x 3 Vectors, 0x00000000000cfd8c>
169
+ # Language Creator Released
170
+ # <string> <string> <uint16>
171
+ # 0 Ruby Yukihiro Matsumoto 1995
172
+ # 1 Python Guido van Rossum 1991
173
+ # 2 R Ross Ihaka and Robert Gentleman 1993
174
+ # 3 Rust Graydon Hoare 2001
175
+ #
176
+ # languages.drop(:Language)
177
+ #
178
+ # # =>
179
+ # #<RedAmber::DataFrame : 4 x 2 Vectors, 0x000000000005805c>
180
+ # Creator Released
181
+ # <string> <uint16>
182
+ # 0 Yukihiro Matsumoto 1995
183
+ # 1 Guido van Rossum 1991
184
+ # 2 Ross Ihaka and Robert Gentleman 1993
185
+ # 3 Graydon Hoare 2001
84
186
  #
85
187
  # @overload drop(booleans)
86
- # Drop variables by booleans.
188
+ # Drop off variables by booleans.
87
189
  #
88
- # @param booleans [<true, false, nil>]
89
- # boolean array of variables to drop at true.
190
+ # @param booleans [<Booleans, nil>, Vector]
191
+ # boolean array or vector of variables to drop at true.
90
192
  # @return [DataFrame]
91
- # Remainer DataFrame.
193
+ # remainer DataFrame.
194
+ # @example Drop off by booleans
195
+ # is_numeric = languages.vectors.map(&:numeric?) # [nil, nil, true]
196
+ # languages.drop(is_numeric)
197
+ #
198
+ # # =>
199
+ # #<RedAmber::DataFrame : 4 x 2 Vectors, 0x0000000000066a1c>
200
+ # Language Creator
201
+ # <string> <string>
202
+ # 0 Ruby Yukihiro Matsumoto
203
+ # 1 Python Guido van Rossum
204
+ # 2 R Ross Ihaka and Robert Gentleman
205
+ # 3 Rust Graydon Hoare
92
206
  #
93
207
  # @overload drop(indices)
94
- # Pick variables by column indices.
208
+ # Drop off variables by column indices.
95
209
  #
96
210
  # @param indices [Integer, Float, Range<Integer>, Vector, Arrow::Array]
97
211
  # numeric array of variables to drop by column index.
98
212
  # @return [DataFrame]
99
- # Remainer DataFrame.
213
+ # remainer DataFrame.
214
+ # @example Drop off by indices
215
+ # languages.drop(2)
216
+ #
217
+ # # =>
218
+ # #<RedAmber::DataFrame : 4 x 2 Vectors, 0x0000000000066a1c>
219
+ # Language Creator
220
+ # <string> <string>
221
+ # 0 Ruby Yukihiro Matsumoto
222
+ # 1 Python Guido van Rossum
223
+ # 2 R Ross Ihaka and Robert Gentleman
224
+ # 3 Rust Graydon Hoare
225
+ #
226
+ # @overload drop
227
+ # Drop off variables by the yielded value from the block.
228
+ # @note Arguments and a block cannot be used simultaneously.
229
+ #
230
+ # @yield [self] the block is called within the context of self.
231
+ # (Block is called by instance_eval(&block). )
232
+ # @yieldreturn [keys, booleans, indices]
233
+ # returns keys, booleans or indices just same as arguments.
234
+ # @return [DataFrame]
235
+ # remainer DataFrame.
236
+ # @example Drop off by a block.
237
+ # # same as languages.drop { |df| df.vectors.map(&:numeric?) }
238
+ # languages.drop { vectors.map(&:numeric?) }
239
+ #
240
+ # # =>
241
+ # #<RedAmber::DataFrame : 4 x 2 Vectors, 0x0000000000154104>
242
+ # Language Creator
243
+ # <string> <string>
244
+ # 0 Ruby Yukihiro Matsumoto
245
+ # 1 Python Guido van Rossum
246
+ # 2 R Ross Ihaka and Robert Gentleman
247
+ # 3 Rust Graydon Hoare
100
248
  #
101
249
  def drop(*args, &block)
102
250
  if block
@@ -109,21 +257,21 @@ module RedAmber
109
257
  return self if args.empty? || empty?
110
258
 
111
259
  picker =
112
- if args.symbols?
260
+ if args.symbol?
113
261
  keys - args
114
- elsif args.booleans?
262
+ elsif args.boolean?
115
263
  keys.reject_by_booleans(args)
116
- elsif args.integers?
264
+ elsif args.integer?
117
265
  keys.reject_by_indices(args)
118
266
  else
119
267
  dropper = parse_args(args, n_keys)
120
- if dropper.booleans?
268
+ if dropper.boolean?
121
269
  keys.reject_by_booleans(dropper)
122
- elsif dropper.symbols?
270
+ elsif dropper.symbol?
123
271
  keys - dropper
124
272
  else
125
273
  dropper.compact!
126
- unless dropper.integers?
274
+ unless dropper.integer?
127
275
  raise DataFrameArgumentError, "Invalid argument #{args}"
128
276
  end
129
277
 
@@ -136,7 +284,85 @@ module RedAmber
136
284
  DataFrame.create(@table.select_columns(*picker))
137
285
  end
138
286
 
139
- # rename variables to create a new DataFrame
287
+ # rename keys (variable/column names) to create a updated DataFrame.
288
+ #
289
+ # @overload rename(key_pairs)
290
+ # Rename by key pairs as a Hash.
291
+ #
292
+ # @param key_pairs [Hash{existing_key => new_key}]
293
+ # key pair(s) of existing name and new name.
294
+ # @return [DataFrame]
295
+ # renamed DataFrame.
296
+ # @example Rename by a Hash
297
+ # comecome
298
+ #
299
+ # # =>
300
+ # #<RedAmber::DataFrame : 3 x 2 Vectors, 0x00000000000037b4>
301
+ # name age
302
+ # <string> <uint8>
303
+ # 0 Yasuko 68
304
+ # 1 Rui 49
305
+ # 2 Hinata 28
306
+ #
307
+ # comecome.rename(:age => :age_in_1993)
308
+ #
309
+ # # =>
310
+ # #<RedAmber::DataFrame : 3 x 2 Vectors, 0x00000000000037c8>
311
+ # name age_in_1993
312
+ # <string> <uint8>
313
+ # 0 Yasuko 68
314
+ # 1 Rui 49
315
+ # 2 Hinata 28
316
+ #
317
+ # @overload rename(key_pairs)
318
+ # Rename by key pairs as an Array of Array.
319
+ #
320
+ # @param key_pairs [<Array[existing_key, new_key]>]
321
+ # key pair(s) of existing name and new name.
322
+ # @return [DataFrame]
323
+ # renamed DataFrame.
324
+ # @example Rename by an Array
325
+ # renamer = [[:name, :heroine], [:age, :age_in_1993]]
326
+ # comecome.rename(renamer)
327
+ #
328
+ # # =>
329
+ # #<RedAmber::DataFrame : 3 x 2 Vectors, 0x00000000000037dc>
330
+ # heroine age_in_1993
331
+ # <string> <uint8>
332
+ # 0 Yasuko 68
333
+ # 1 Rui 49
334
+ # 2 Hinata 28
335
+ #
336
+ # @overload rename
337
+ # Rename by key pairs yielding from block.
338
+ #
339
+ # @yield [self] the block is called within the context of self.
340
+ # (Block is called by instance_eval(&block). )
341
+ # @yieldreturn [<[existing_key, new_key]>, Hash]
342
+ # returns an Array or a Hash just same as arguments.
343
+ # @return [DataFrame]
344
+ # renamed DataFrame.
345
+ # @example Rename by block.
346
+ # df
347
+ #
348
+ # # =>
349
+ # #<RedAmber::DataFrame : 2 x 3 Vectors, 0x000000000000c29c>
350
+ # X Y Z
351
+ # <uint8> <uint8> <uint8>
352
+ # 0 1 3 5
353
+ # 1 2 4 6
354
+ #
355
+ # df.rename { keys.zip(keys.map(&:downcase)) }
356
+ # # or
357
+ # df.rename { [keys, keys.map(&:downcase)].transpose }
358
+ #
359
+ # # =>
360
+ # #<RedAmber::DataFrame : 2 x 3 Vectors, 0x000000000000c364>
361
+ # x y z
362
+ # <uint8> <uint8> <uint8>
363
+ # 0 1 3 5
364
+ # 1 2 4 6
365
+ #
140
366
  def rename(*renamer, &block)
141
367
  if block
142
368
  unless renamer.empty?
@@ -162,11 +388,197 @@ module RedAmber
162
388
  rename_by_hash(key_pairs)
163
389
  end
164
390
 
165
- # assign variables to create a new DataFrame
391
+ # Assign new or updated variables (columns) and create an updated DataFrame.
392
+ # - Array-like variables with new keys will append new columns from right.
393
+ # - Array-like variables with exisiting keys will update corresponding vectors.
394
+ # - Symbol key and String key are considered as the same key.
395
+ # - If assigner is empty or nil, returns self.
396
+ #
397
+ # @overload assign(key_value_pairs)
398
+ # accepts pairs of key and values by an Array or a Hash.
399
+ #
400
+ # @param key_value_pairs [Array<key, array_like>, Hash{key => array_like}]
401
+ # `key` must be a Symbol or a String.
402
+ # `array_like` is column data to be assigned.
403
+ # It must be one of `Vector` or `Arrow::Array` or `Array`.
404
+ # @return [DataFrame]
405
+ # assigned DataFrame.
406
+ # @example Assign a new column
407
+ # comecome
408
+ #
409
+ # # =>
410
+ # #<RedAmber::DataFrame : 3 x 2 Vectors, 0x00000000000280dc>
411
+ # name age
412
+ # <string> <uint8>
413
+ # 0 Yasuko 68
414
+ # 1 Rui 49
415
+ # 2 Hinata 28
416
+ #
417
+ # brothers = ['Santa', nil, 'Momotaro']
418
+ # comecome.assign(brother: brothers)
419
+ # # or
420
+ # comecome.assign({ brother: brothers })
421
+ # # or
422
+ # comecome.assign(:brother, brothers)
423
+ # # or
424
+ # comecome.assign([:brother, brothers])
425
+ #
426
+ # # =>
427
+ # #<RedAmber::DataFrame : 3 x 3 Vectors, 0x000000000004077c>
428
+ # name age brother
429
+ # <string> <uint8> <string>
430
+ # 0 Yasuko 68 Santa
431
+ # 1 Rui 49 (nil)
432
+ # 2 Hinata 28 Momotaro
433
+ #
434
+ # @example Assign new data for a existing column
435
+ # comecome.assign(age: comecome[:age] + 29)
436
+ #
437
+ # # =>
438
+ # #<RedAmber::DataFrame : 3 x 2 Vectors, 0x0000000000065860>
439
+ # name age
440
+ # <string> <uint8>
441
+ # 0 Yasuko 97
442
+ # 1 Rui 78
443
+ # 2 Hinata 57
444
+ #
445
+ # @overload assign
446
+ # accepts block yielding pairs of key and values.
447
+ #
448
+ # @yield [self]
449
+ # the block is called within the context of self.
450
+ # (Block is called by instance_eval(&block). )
451
+ # @yieldreturn [Array<key, array_like>, Hash(key => array_like)]
452
+ # `key` must be a Symbol or a String.
453
+ # `array_like` is column data to be assigned.
454
+ # It must be one of `Vector` or `Arrow::Array` or `Array`.
455
+ # @return [DataFrame]
456
+ # assigned DataFrame.
457
+ # @example Assign new data for a existing column by block
458
+ # comecome.assign { { age: age + 29 } }
459
+ # # or
460
+ # comecome.assign { [:age, age + 29] }
461
+ # # or
462
+ # comecome.assign { [[:age, age + 29]] }
463
+ #
464
+ # # =>
465
+ # #<RedAmber::DataFrame : 3 x 2 Vectors, 0x000000000007d640>
466
+ # name age
467
+ # <string> <uint8>
468
+ # 0 Yasuko 97
469
+ # 1 Rui 78
470
+ # 2 Hinata 57
471
+ #
472
+ # @overload assign(keys)
473
+ # accepts keys from argument and pairs of key and values from block.
474
+ #
475
+ # @param keys [Symbol, String] keys of columns to create or update.
476
+ # @yield [self]
477
+ # the block is called within the context of self.
478
+ # (Block is called by instance_eval(&block).)
479
+ # @yieldreturn [Array<array_like>]
480
+ # column data to be assigned.
481
+ # `array_like` must be one of `Vector` or `Arrow::Array` or `Array`.
482
+ # @return [DataFrame]
483
+ # assigned DataFrame.
484
+ # @example Assign new data for a existing column by block
485
+ # comecome.assign(:age) { age + 29 }
486
+ #
487
+ # # =>
488
+ # #<RedAmber::DataFrame : 3 x 2 Vectors, 0x000000000007af94>
489
+ # name age
490
+ # <string> <uint8>
491
+ # 0 Yasuko 97
492
+ # 1 Rui 78
493
+ # 2 Hinata 57
494
+ #
495
+ # @example Assign multiple data
496
+ # comecome.assign(:age_in_1993, :brother) do
497
+ # [
498
+ # age + 29,
499
+ # ['Santa', nil, 'Momotaro'],
500
+ # ]
501
+ # end
502
+ #
503
+ # # =>
504
+ # #<RedAmber::DataFrame : 3 x 4 Vectors, 0x00000000000b363c>
505
+ # name age age_in_1993 brother
506
+ # <string> <uint8> <uint8> <string>
507
+ # 0 Yasuko 68 97 Santa
508
+ # 1 Rui 49 78 (nil)
509
+ # 2 Hinata 28 57 Momotaro
510
+ #
166
511
  def assign(*assigner, &block)
167
512
  assign_update(*assigner, append_to_left: false, &block)
168
513
  end
169
514
 
515
+ # Assign new or updated variables (columns) and create an updated DataFrame.
516
+ # - Array-like variables with new keys will append new columns from left.
517
+ # - Array-like variables with exisiting keys will update corresponding vectors.
518
+ # - Symbol key and String key are considered as the same key.
519
+ # - If assigner is empty or nil, returns self.
520
+ #
521
+ # @overload assign_left(key_value_pairs)
522
+ # accepts pairs of key and values by an Array or a Hash.
523
+ #
524
+ # @param key_value_pairs [Array<key, array_like>, Hash{key => array_like}]
525
+ # `key` must be a Symbol or a String.
526
+ # `array_like` is column data to be assigned.
527
+ # It must be one of `Vector` or `Arrow::Array` or `Array`.
528
+ # @return [DataFrame]
529
+ # assigned DataFrame.
530
+ # @example Assign a new column from left
531
+ # df
532
+ #
533
+ # # =>
534
+ # #<RedAmber::DataFrame : 5 x 3 Vectors, 0x000000000000c10c>
535
+ # index float string
536
+ # <uint8> <double> <string>
537
+ # 0 0 0.0 A
538
+ # 1 1 1.1 B
539
+ # 2 2 2.2 C
540
+ # 3 3 NaN D
541
+ # 4 (nil) (nil) (nil)
542
+ #
543
+ # df.assign_left(new_index: df.indices(1))
544
+ #
545
+ # # =>
546
+ # #<RedAmber::DataFrame : 5 x 4 Vectors, 0x000000000001787c>
547
+ # new_index index float string
548
+ # <uint8> <uint8> <double> <string>
549
+ # 0 1 0 0.0 A
550
+ # 1 2 1 1.1 B
551
+ # 2 3 2 2.2 C
552
+ # 3 4 3 NaN D
553
+ # 4 5 (nil) (nil) (nil)
554
+ #
555
+ # @overload assign_left
556
+ # accepts block yielding pairs of key and values.
557
+ #
558
+ # @yield [self]
559
+ # the block is called within the context of self.
560
+ # (Block is called by instance_eval(&block). )
561
+ # @yieldreturn [Array<key, array_like>, Hash(key => array_like)]
562
+ # `key` must be a Symbol or a String.
563
+ # `array_like` is column data to be assigned.
564
+ # It must be one of `Vector` or `Arrow::Array` or `Array`.
565
+ # @return [DataFrame]
566
+ # assigned DataFrame.
567
+ #
568
+ # @overload assign_left(keys)
569
+ # accepts keys from argument and pairs of key and values from block.
570
+ #
571
+ # @param keys [Symbol, String]
572
+ # keys of columns to create or update.
573
+ # @yield [self]
574
+ # the block is called within the context of self.
575
+ # (Block is called by instance_eval(&block).)
576
+ # @yieldreturn [Array<array_like>]
577
+ # column data to be assigned.
578
+ # `array_like` must be one of `Vector` or `Arrow::Array` or `Array`.
579
+ # @return [DataFrame]
580
+ # assigned DataFrame.
581
+ #
170
582
  def assign_left(*assigner, &block)
171
583
  assign_update(*assigner, append_to_left: true, &block)
172
584
  end