daru 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -7
  3. data/CONTRIBUTING.md +1 -1
  4. data/History.md +48 -1
  5. data/README.md +3 -3
  6. data/benchmarks/statistics.rb +6 -6
  7. data/benchmarks/where_clause.rb +1 -1
  8. data/benchmarks/where_vs_filter.rb +1 -1
  9. data/daru.gemspec +3 -2
  10. data/lib/daru.rb +14 -6
  11. data/lib/daru/accessors/gsl_wrapper.rb +1 -1
  12. data/lib/daru/accessors/nmatrix_wrapper.rb +2 -0
  13. data/lib/daru/category.rb +1 -1
  14. data/lib/daru/core/group_by.rb +32 -15
  15. data/lib/daru/core/query.rb +4 -4
  16. data/lib/daru/dataframe.rb +196 -48
  17. data/lib/daru/date_time/index.rb +7 -5
  18. data/lib/daru/formatters/table.rb +1 -0
  19. data/lib/daru/index/index.rb +121 -33
  20. data/lib/daru/index/multi_index.rb +83 -3
  21. data/lib/daru/io/csv/converters.rb +18 -0
  22. data/lib/daru/io/io.rb +80 -11
  23. data/lib/daru/io/sql_data_source.rb +10 -0
  24. data/lib/daru/iruby/templates/dataframe.html.erb +3 -50
  25. data/lib/daru/iruby/templates/dataframe_mi.html.erb +3 -56
  26. data/lib/daru/iruby/templates/dataframe_mi_tbody.html.erb +35 -0
  27. data/lib/daru/iruby/templates/dataframe_mi_thead.html.erb +21 -0
  28. data/lib/daru/iruby/templates/dataframe_tbody.html.erb +28 -0
  29. data/lib/daru/iruby/templates/dataframe_thead.html.erb +21 -0
  30. data/lib/daru/iruby/templates/vector.html.erb +3 -25
  31. data/lib/daru/iruby/templates/vector_mi.html.erb +3 -34
  32. data/lib/daru/iruby/templates/vector_mi_tbody.html.erb +26 -0
  33. data/lib/daru/iruby/templates/vector_mi_thead.html.erb +8 -0
  34. data/lib/daru/iruby/templates/vector_tbody.html.erb +17 -0
  35. data/lib/daru/iruby/templates/vector_thead.html.erb +8 -0
  36. data/lib/daru/maths/statistics/dataframe.rb +9 -11
  37. data/lib/daru/maths/statistics/vector.rb +139 -32
  38. data/lib/daru/plotting/gruff/dataframe.rb +13 -15
  39. data/lib/daru/plotting/nyaplot/category.rb +1 -1
  40. data/lib/daru/plotting/nyaplot/dataframe.rb +4 -4
  41. data/lib/daru/plotting/nyaplot/vector.rb +1 -2
  42. data/lib/daru/vector.rb +169 -80
  43. data/lib/daru/version.rb +1 -1
  44. data/spec/category_spec.rb +19 -19
  45. data/spec/core/group_by_spec.rb +47 -0
  46. data/spec/core/query_spec.rb +55 -50
  47. data/spec/daru_spec.rb +22 -0
  48. data/spec/dataframe_spec.rb +118 -6
  49. data/spec/date_time/index_spec.rb +34 -16
  50. data/spec/extensions/rserve_spec.rb +1 -1
  51. data/spec/fixtures/boolean_converter_test.csv +5 -0
  52. data/spec/fixtures/eciresults.html +394 -0
  53. data/spec/fixtures/empty_rows_test.csv +17 -0
  54. data/spec/fixtures/macau.html +3691 -0
  55. data/spec/fixtures/macd_data.csv +150 -0
  56. data/spec/fixtures/moneycontrol.html +6812 -0
  57. data/spec/fixtures/url_test.txt~ +0 -0
  58. data/spec/fixtures/valid_markup.html +62 -0
  59. data/spec/fixtures/wiki_climate.html +1243 -0
  60. data/spec/fixtures/wiki_table_info.html +631 -0
  61. data/spec/formatters/table_formatter_spec.rb +29 -0
  62. data/spec/index/categorical_index_spec.rb +33 -33
  63. data/spec/index/index_spec.rb +134 -41
  64. data/spec/index/multi_index_spec.rb +115 -31
  65. data/spec/io/io_spec.rb +201 -0
  66. data/spec/io/sql_data_source_spec.rb +31 -41
  67. data/spec/iruby/dataframe_spec.rb +17 -19
  68. data/spec/iruby/vector_spec.rb +26 -28
  69. data/spec/maths/statistics/vector_spec.rb +136 -14
  70. data/spec/plotting/gruff/category_spec.rb +3 -3
  71. data/spec/plotting/gruff/dataframe_spec.rb +14 -4
  72. data/spec/plotting/gruff/vector_spec.rb +9 -9
  73. data/spec/plotting/nyaplot/category_spec.rb +5 -9
  74. data/spec/plotting/nyaplot/dataframe_spec.rb +72 -47
  75. data/spec/plotting/nyaplot/vector_spec.rb +5 -11
  76. data/spec/shared/vector_display_spec.rb +12 -14
  77. data/spec/spec_helper.rb +21 -0
  78. data/spec/support/matchers.rb +5 -0
  79. data/spec/vector_spec.rb +222 -72
  80. metadata +68 -23
  81. data/spec/fixtures/stock_data.csv +0 -500
@@ -35,6 +35,54 @@ describe Daru::MultiIndex do
35
35
  labels: [[0,0,1,1,2,2]])
36
36
  }.to raise_error
37
37
  end
38
+
39
+ context "create an MultiIndex with name" do
40
+ context 'if no name is set' do
41
+ subject { Daru::MultiIndex.new(
42
+ levels: [[:a,:b,:c], [:one, :two]],
43
+ labels: [[0,0,1,1,2,2], [0,1,0,1,0,1]]) }
44
+ its(:name) { is_expected.to be_nil }
45
+ end
46
+
47
+ context 'correctly return the MultiIndex name' do
48
+ subject { Daru::MultiIndex.new(
49
+ levels: [[:a,:b,:c], [:one, :two]],
50
+ labels: [[0,0,1,1,2,2], [0,1,0,1,0,1]], name: ['n1', 'n2']) }
51
+ its(:name) { is_expected.to eq ['n1', 'n2'] }
52
+ end
53
+
54
+ context "set new MultiIndex name" do
55
+ subject {
56
+ Daru::MultiIndex.new(
57
+ levels: [[:a,:b,:c], [:one, :two]],
58
+ labels: [[0,0,1,1,2,2], [0,1,0,1,0,1]], name: ['n1', 'n2']) }
59
+ before(:each) { subject.name = ['k1', 'k2'] }
60
+ its(:name) { is_expected.to eq ['k1', 'k2'] }
61
+ end
62
+
63
+ context "set new MultiIndex name having empty string" do
64
+ subject {
65
+ Daru::MultiIndex.new(
66
+ levels: [[:a,:b,:c], [:one, :two]],
67
+ labels: [[0,0,1,1,2,2], [0,1,0,1,0,1]], name: ['n1', 'n2']) }
68
+ before { subject.name = ['k1', ''] }
69
+ its(:name) { is_expected.to eq ['k1', ''] }
70
+ end
71
+
72
+ it "raises SizeError for wrong number of name" do
73
+ error_msg = "\'names\' and \'levels\' should be of same size. Size of the \'name\' array is 2 and size of the MultiIndex \'levels\' and \'labels\' is 3.\nIf you don\'t want to set name for particular level (say level \'i\') then put empty string on index \'i\' of the \'name\' Array."
74
+ expect { @multi_mi.name = ['n1', 'n2'] }.to raise_error(SizeError, error_msg)
75
+
76
+ error_msg = "'names' and 'levels' should be of same size. Size of the 'name' array is 0 and size of the MultiIndex 'levels' and 'labels' is 3.\nIf you don\'t want to set name for particular level (say level 'i') then put empty string on index 'i' of the 'name' Array."
77
+ expect { @multi_mi.name = [ ] }.to raise_error(SizeError, error_msg)
78
+
79
+ error_msg = "'names' and 'levels' should be of same size. Size of the 'name' array is 1 and size of the MultiIndex 'levels' and 'labels' is 3.\nIf you don\'t want to set name for particular level (say level 'i') then put empty string on index 'i' of the 'name' Array."
80
+ expect { @multi_mi.name = [''] }.to raise_error(SizeError, error_msg)
81
+
82
+ error_msg = "'names' and 'levels' should be of same size. Size of the 'name' array is 4 and size of the MultiIndex 'levels' and 'labels' is 3."
83
+ expect { @multi_mi.name = ['n1', 'n2', 'n3', 'n4'] }.to raise_error(SizeError, error_msg)
84
+ end
85
+ end
38
86
  end
39
87
 
40
88
  context ".from_tuples" do
@@ -255,6 +303,42 @@ describe Daru::MultiIndex do
255
303
  }.unindent
256
304
  }
257
305
  end
306
+
307
+ context 'multi index with name' do
308
+ subject {
309
+ Daru::MultiIndex.new(
310
+ levels: [[:a,:b,:c],[:one,:two],[:bar, :baz, :foo]],
311
+ labels: [
312
+ [0,0,0,0,1,1,1,1,2,2,2,2],
313
+ [0,0,1,1,0,1,1,0,0,0,1,1],
314
+ [0,1,0,1,0,0,1,2,0,1,2,0]], name: ['n1', 'n2', 'n3'])
315
+ }
316
+
317
+ its(:inspect) { is_expected.to start_with %Q{
318
+ |#<Daru::MultiIndex(12x3)>
319
+ | n1 n2 n3
320
+ }.unindent
321
+ }
322
+ end
323
+
324
+ context 'multi index with name having empty string' do
325
+ subject {
326
+ mi= Daru::MultiIndex.new(
327
+ levels: [[:a,:b,:c],[:one,:two],[:bar, :baz, :foo]],
328
+ labels: [
329
+ [0,0,0,0,1,1,1,1,2,2,2,2],
330
+ [0,0,1,1,0,1,1,0,0,0,1,1],
331
+ [0,1,0,1,0,0,1,2,0,1,2,0]], name: ['n1', 'n2', 'n3'])
332
+ }
333
+ before { subject.name = ['n1', '', 'n3'] }
334
+
335
+ its(:inspect) { is_expected.to start_with %Q{
336
+ |#<Daru::MultiIndex(12x3)>
337
+ | n1 n3
338
+ }.unindent
339
+ }
340
+ end
341
+
258
342
  end
259
343
 
260
344
  context "#==" do
@@ -410,31 +494,31 @@ describe Daru::MultiIndex do
410
494
  [:b,:one,:foo]
411
495
  ])
412
496
  end
413
-
497
+
414
498
  context "single index" do
415
499
  it { expect(idx.pos :b, :one, :bar).to eq 0 }
416
500
  end
417
-
501
+
418
502
  context "multiple indexes" do
419
503
  subject { idx.pos :b, :one }
420
-
504
+
421
505
  it { is_expected.to be_a Array }
422
506
  its(:size) { is_expected.to eq 2 }
423
507
  it { is_expected.to eq [0, 3] }
424
508
  end
425
-
509
+
426
510
  context "single positional index" do
427
511
  it { expect(idx.pos 0).to eq 0 }
428
512
  end
429
-
513
+
430
514
  context "multiple positional indexes" do
431
515
  subject { idx.pos 0, 1 }
432
-
516
+
433
517
  it { is_expected.to be_a Array }
434
518
  its(:size) { is_expected.to eq 2 }
435
519
  it { is_expected.to eq [0, 1] }
436
520
  end
437
-
521
+
438
522
  # TODO: Add specs for IndexError
439
523
  end
440
524
 
@@ -447,23 +531,23 @@ describe Daru::MultiIndex do
447
531
  [:b, :one, :foo]
448
532
  ])
449
533
  end
450
-
534
+
451
535
  context "multiple indexes" do
452
536
  subject { idx.subset :b, :one }
453
-
537
+
454
538
  it { is_expected.to be_a described_class }
455
539
  its(:size) { is_expected.to eq 2 }
456
540
  its(:to_a) { is_expected.to eq [[:bar], [:foo]] }
457
541
  end
458
-
542
+
459
543
  context "multiple positional indexes" do
460
544
  subject { idx.subset 0, 1 }
461
-
545
+
462
546
  it { is_expected.to be_a described_class }
463
547
  its(:size) { is_expected.to eq 2 }
464
548
  its(:to_a) { is_expected.to eq [[:b, :one, :bar], [:b, :two, :bar]] }
465
549
  end
466
-
550
+
467
551
  # TODO: Checks for invalid indexes
468
552
  end
469
553
 
@@ -476,53 +560,53 @@ describe Daru::MultiIndex do
476
560
  [:b, :one, :foo]
477
561
  ])
478
562
  end
479
-
563
+
480
564
  context "single position" do
481
565
  it { expect(idx.at 2).to eq [:b, :two, :baz] }
482
566
  end
483
-
567
+
484
568
  context "multiple positions" do
485
569
  subject { idx.at 1, 2 }
486
-
570
+
487
571
  it { is_expected.to be_a described_class }
488
572
  its(:size) { is_expected.to eq 2 }
489
573
  its(:to_a) { is_expected.to eq [[:b, :two, :bar],
490
574
  [:b, :two, :baz]] }
491
575
  end
492
-
576
+
493
577
  context "range" do
494
578
  subject { idx.at 1..2 }
495
-
579
+
496
580
  it { is_expected.to be_a described_class }
497
581
  its(:size) { is_expected.to eq 2 }
498
582
  its(:to_a) { is_expected.to eq [[:b, :two, :bar],
499
- [:b, :two, :baz]] }
583
+ [:b, :two, :baz]] }
500
584
  end
501
-
585
+
502
586
  context "range with negative integers" do
503
587
  subject { idx.at 1..-2 }
504
-
588
+
505
589
  it { is_expected.to be_a described_class }
506
590
  its(:size) { is_expected.to eq 2 }
507
591
  its(:to_a) { is_expected.to eq [[:b, :two, :bar],
508
- [:b, :two, :baz]] }
509
- end
510
-
592
+ [:b, :two, :baz]] }
593
+ end
594
+
511
595
  context "rangle with single element" do
512
596
  subject { idx.at 1..1 }
513
-
597
+
514
598
  it { is_expected.to be_a described_class }
515
599
  its(:size) { is_expected.to eq 1 }
516
600
  its(:to_a) { is_expected.to eq [[:b, :two, :bar]] }
517
601
  end
518
-
602
+
519
603
  context "invalid position" do
520
604
  it { expect { idx.at 4 }.to raise_error IndexError }
521
605
  end
522
-
606
+
523
607
  context "invalid positions" do
524
608
  it { expect { idx.at 2, 4 }.to raise_error IndexError }
525
- end
609
+ end
526
610
  end
527
611
 
528
612
  context "#add" do
@@ -534,7 +618,7 @@ describe Daru::MultiIndex do
534
618
  [:b, :one, :foo]
535
619
  ]
536
620
  end
537
-
621
+
538
622
  context "single index" do
539
623
  subject { idx.add :b, :two, :baz }
540
624
 
@@ -556,15 +640,15 @@ describe Daru::MultiIndex do
556
640
  [:b, :one, :foo]
557
641
  ]
558
642
  end
559
-
643
+
560
644
  context "single index" do
561
645
  it { expect(idx.valid? :a, :one, :bar).to eq true }
562
646
  it { expect(idx.valid? :b, :two, :three).to eq false }
563
647
  end
564
-
648
+
565
649
  context "multiple indexes" do
566
650
  it { expect(idx.valid? :a, :one).to eq true }
567
651
  it { expect(idx.valid? :a, :three).to eq false }
568
652
  end
569
- end
653
+ end
570
654
  end
@@ -1,6 +1,14 @@
1
1
  describe Daru::IO do
2
2
  describe Daru::DataFrame do
3
3
  context ".from_csv" do
4
+ before do
5
+ %w[matrix_test repeated_fields scientific_notation sales-funnel].each do |file|
6
+ WebMock
7
+ .stub_request(:get,"http://dummy-remote-url/#{file}.csv")
8
+ .to_return(status: 200, body: File.read("spec/fixtures/#{file}.csv"))
9
+ end
10
+ end
11
+
4
12
  it "loads from a CSV file" do
5
13
  df = Daru::DataFrame.from_csv('spec/fixtures/matrix_test.csv',
6
14
  col_sep: ' ', headers: true)
@@ -32,6 +40,24 @@ describe Daru::IO do
32
40
  df = Daru::DataFrame.from_csv 'spec/fixtures/sales-funnel.csv'
33
41
  expect(df.vectors.to_a).to eq(%W[Account Name Rep Manager Product Quantity Price Status])
34
42
  end
43
+
44
+ it "handles empty rows in the CSV" do
45
+ df = Daru::DataFrame.from_csv 'spec/fixtures/empty_rows_test.csv'
46
+ expect(df.nrows).to eq(13)
47
+ end
48
+
49
+ it "uses the custom boolean converter correctly" do
50
+ df = Daru::DataFrame.from_csv 'spec/fixtures/boolean_converter_test.csv', converters: [:boolean]
51
+ expect(df['Domestic'].to_a).to all be_boolean
52
+ end
53
+
54
+ it "checks for equal parsing of local CSV files and remote CSV files" do
55
+ %w[matrix_test repeated_fields scientific_notation sales-funnel].each do |file|
56
+ df_local = Daru::DataFrame.from_csv("spec/fixtures/#{file}.csv")
57
+ df_remote = Daru::DataFrame.from_csv("http://dummy-remote-url/#{file}.csv")
58
+ expect(df_local).to eq(df_remote)
59
+ end
60
+ end
35
61
  end
36
62
 
37
63
  context "#write_csv" do
@@ -269,6 +295,181 @@ describe Daru::IO do
269
295
  expect(a).to eq(@data_frame)
270
296
  end
271
297
  end
298
+
299
+ context "#from_html" do
300
+ context "in wiki info table" do
301
+ let(:path) { "file://#{Dir.pwd}/spec/fixtures/wiki_table_info.html" }
302
+ let(:order) { ["FName", "LName", "Age"] }
303
+ let(:index) { ["One", "Two", "Three", "Four", "Five", "Six", "Seven"] }
304
+ let(:name) { "Wikipedia Information Table" }
305
+
306
+ context "returns default dataframe" do
307
+ subject { Daru::DataFrame.from_html(path) }
308
+
309
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
310
+ its(:first) { is_expected.to eq (Daru::DataFrame.new(
311
+ [["Tinu", "Blaszczyk", "Lily", "Olatunkboh", "Adrienne", "Axelia", "Jon-Kabat"],
312
+ ["Elejogun", "Kostrzewski", "McGarrett", "Chijiaku", "Anthoula", "Athanasios", "Zinn"],
313
+ ["14", "25", "16", "22", "22", "22", "22"]],
314
+ order: ["First name","Last name","Age"]
315
+ )
316
+ )
317
+ }
318
+ end
319
+
320
+ context "returns user-modified dataframe" do
321
+ subject { Daru::DataFrame.from_html(path, order: order, index: index, name: name) }
322
+
323
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
324
+ its(:first) { is_expected.to eq(Daru::DataFrame.new(
325
+ [["Tinu", "Blaszczyk", "Lily", "Olatunkboh", "Adrienne", "Axelia", "Jon-Kabat"],
326
+ ["Elejogun", "Kostrzewski", "McGarrett", "Chijiaku", "Anthoula", "Athanasios", "Zinn"],
327
+ ["14", "25", "16", "22", "22", "22", "22"]],
328
+ order: ["FName","LName", "Age"],
329
+ index: ["One", "Two", "Three", "Four", "Five", "Six", "Seven"],
330
+ name: "Wikipedia Information Table"
331
+ )
332
+ )
333
+ }
334
+ end
335
+ end
336
+
337
+ context "in wiki climate data" do
338
+ let(:path) { "file://#{Dir.pwd}/spec/fixtures/wiki_climate.html" }
339
+
340
+ context "returns default dataframe" do
341
+ subject { Daru::DataFrame.from_html(path) }
342
+
343
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
344
+ its('first.index') { is_expected.to eq(Daru::Index.new(
345
+ ["Record high °C (°F)", "Average high °C (°F)", "Daily mean °C (°F)", "Average low °C (°F)", "Record low °C (°F)", "Average rainfall mm (inches)", "Average rainy days", "Average relative humidity (%)", "Mean monthly sunshine hours", "Mean daily sunshine hours"]
346
+ )
347
+ )
348
+ }
349
+
350
+ end
351
+ end
352
+
353
+ context "with valid html table markups" do
354
+ let(:path) { "file://#{Dir.pwd}/spec/fixtures/valid_markup.html" }
355
+ let(:index) { ["W","X","Y","Z"] }
356
+ let(:name) { "Small HTML table with index" }
357
+
358
+ context "returns user-modified dataframe" do
359
+ subject { Daru::DataFrame.from_html(path, index: index, name: name) }
360
+
361
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
362
+ its(:first) { is_expected.to eq(Daru::DataFrame.new(
363
+ [["6", "4","9","7"],["7","0","4","0"]],
364
+ order: ["a","b"],
365
+ index: ["W","X","Y","Z"],
366
+ name: "Small HTML table with index"
367
+ )
368
+ )
369
+ }
370
+ end
371
+ end
372
+
373
+ context "in year-wise passengers figure" do
374
+ let(:path) { "file://#{Dir.pwd}/spec/fixtures/macau.html" }
375
+ let(:match) { "2001" }
376
+ let(:name) { "Year-wise Passengers Figure" }
377
+
378
+ context "returns matching dataframes with index" do
379
+ subject { Daru::DataFrame.from_html(path, match: match, name: name) }
380
+
381
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
382
+ its('first.index') { is_expected.to eq(Daru::Index.new(
383
+ ["January","February","March","April","May","June","July","August","September","October","November","December","Total"]
384
+ )
385
+ )
386
+ }
387
+ its(:first) { is_expected.to eq(Daru::DataFrame.new(
388
+ [
389
+ ["265,603","184,381","161,264","161,432","117,984",""],
390
+ ["249,259","264,066","209,569","168,777","150,772",""],
391
+ ["312,319","226,483","186,965","172,060","149,795",""],
392
+ ["351,793","296,541","237,449","180,241","179,049",""],
393
+ ["338,692","288,949","230,691","172,391","189,925",""],
394
+ ["332,630","271,181","231,328","157,519","175,402",""],
395
+ ["344,658","304,276","243,534","205,595","173,103",""],
396
+ ["360,899","300,418","257,616","241,140","178,118",""],
397
+ ["291,817","280,803","210,885","183,954","163,385",""],
398
+ ["327,232","298,873","231,251","205,726","176,879",""],
399
+ ["315,538","265,528","228,637","181,677","146,804",""],
400
+ ["314,866","257,929","210,922","183,975","151,362",""],
401
+ ["3,805,306","3,239,428","2,640,111","2,214,487","1,952,578","0"]
402
+ ].transpose,
403
+ order: ["2001","2000","1999","1998","1997","1996"],
404
+ index: ["January","February","March","April","May","June","July","August","September","October","November","December","Total"],
405
+ name: "Year-wise Passengers Figure"
406
+ )
407
+ )
408
+ }
409
+ end
410
+ end
411
+
412
+ context "in share market data" do
413
+ let(:path) { "file://#{Dir.pwd}/spec/fixtures/moneycontrol.html" }
414
+ let(:match) { "Sun Pharma" }
415
+ let(:index) { ["Alpha", "Beta", "Gamma", "Delta", "Misc"] }
416
+ let(:name) { "Share Market Analysis" }
417
+
418
+ context "returns matching dataframes" do
419
+ subject { Daru::DataFrame.from_html(path, match: match) }
420
+
421
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
422
+ its(:first) { is_expected.to eq(Daru::DataFrame.new(
423
+ [
424
+ ["Sun Pharma","502.60","-65.05","2,117.87"],
425
+ ["Reliance","1356.90","19.60","745.10"],
426
+ ["Tech Mahindra","379.45","-49.70","650.22"],
427
+ ["ITC","315.85","6.75","621.12"],
428
+ ["HDFC","1598.85","50.95","553.91"]
429
+ ].transpose,
430
+ order: ["Company","Price","Change","Value (Rs Cr.)"]
431
+ )
432
+ )
433
+ }
434
+ end
435
+
436
+ context "returns user-modified matching dataframes" do
437
+ subject { Daru::DataFrame.from_html(path, match: match, index: index, name: name) }
438
+
439
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
440
+ its(:last) { is_expected.to eq(Daru::DataFrame.new(
441
+ [
442
+ ["Sun Pharma","502.60","-65.05","2,117.87"],
443
+ ["Reliance","1356.90","19.60","745.10"],
444
+ ["Tech Mahindra","379.45","-49.70","650.22"],
445
+ ["ITC","315.85","6.75","621.12"],
446
+ ["HDFC","1598.85","50.95","553.91"]
447
+ ].transpose,
448
+ order: ["Company","Price","Change","Value (Rs Cr.)"],
449
+ index: ["Alpha", "Beta", "Gamma", "Delta", "Misc"],
450
+ name: "Share Market Analysis"
451
+ )
452
+ )
453
+ }
454
+ end
455
+
456
+ end
457
+
458
+ context "in election results data" do
459
+ let(:path) { "file://#{Dir.pwd}/spec/fixtures/eciresults.html" }
460
+
461
+ context "returns default dataframes" do
462
+ subject { Daru::DataFrame.from_html(path) }
463
+
464
+ it { is_expected.to be_an(Array).and all be_a(Daru::DataFrame) }
465
+ its('first.vectors') { is_expected.to eq(Daru::Index.new(
466
+ ["PartyName", "Votes Wise(%)"]
467
+ )
468
+ )
469
+ }
470
+ end
471
+ end
472
+ end
272
473
  end
273
474
 
274
475
  describe Daru::Vector do