daru 0.1.5 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +18 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +21 -7
  5. data/.travis.yml +10 -5
  6. data/CONTRIBUTING.md +15 -10
  7. data/History.md +124 -2
  8. data/README.md +37 -9
  9. data/ReleasePolicy.md +20 -0
  10. data/benchmarks/db_loading.rb +34 -0
  11. data/benchmarks/statistics.rb +6 -6
  12. data/benchmarks/where_clause.rb +1 -1
  13. data/benchmarks/where_vs_filter.rb +1 -1
  14. data/daru.gemspec +17 -41
  15. data/lib/daru.rb +10 -13
  16. data/lib/daru/accessors/gsl_wrapper.rb +1 -1
  17. data/lib/daru/accessors/nmatrix_wrapper.rb +2 -0
  18. data/lib/daru/category.rb +29 -15
  19. data/lib/daru/configuration.rb +34 -0
  20. data/lib/daru/core/group_by.rb +158 -77
  21. data/lib/daru/core/merge.rb +12 -3
  22. data/lib/daru/core/query.rb +20 -4
  23. data/lib/daru/dataframe.rb +692 -118
  24. data/lib/daru/date_time/index.rb +14 -11
  25. data/lib/daru/date_time/offsets.rb +9 -1
  26. data/lib/daru/extensions/which_dsl.rb +55 -0
  27. data/lib/daru/formatters/table.rb +3 -5
  28. data/lib/daru/index/categorical_index.rb +4 -4
  29. data/lib/daru/index/index.rb +131 -42
  30. data/lib/daru/index/multi_index.rb +118 -10
  31. data/lib/daru/io/csv/converters.rb +21 -0
  32. data/lib/daru/io/io.rb +105 -33
  33. data/lib/daru/io/sql_data_source.rb +10 -0
  34. data/lib/daru/iruby/templates/dataframe.html.erb +4 -51
  35. data/lib/daru/iruby/templates/dataframe_mi.html.erb +3 -56
  36. data/lib/daru/iruby/templates/dataframe_mi_tbody.html.erb +35 -0
  37. data/lib/daru/iruby/templates/dataframe_mi_thead.html.erb +21 -0
  38. data/lib/daru/iruby/templates/dataframe_tbody.html.erb +28 -0
  39. data/lib/daru/iruby/templates/dataframe_thead.html.erb +21 -0
  40. data/lib/daru/iruby/templates/vector.html.erb +3 -25
  41. data/lib/daru/iruby/templates/vector_mi.html.erb +3 -34
  42. data/lib/daru/iruby/templates/vector_mi_tbody.html.erb +26 -0
  43. data/lib/daru/iruby/templates/vector_mi_thead.html.erb +8 -0
  44. data/lib/daru/iruby/templates/vector_tbody.html.erb +17 -0
  45. data/lib/daru/iruby/templates/vector_thead.html.erb +8 -0
  46. data/lib/daru/maths/arithmetic/vector.rb +38 -2
  47. data/lib/daru/maths/statistics/dataframe.rb +28 -30
  48. data/lib/daru/maths/statistics/vector.rb +295 -41
  49. data/lib/daru/plotting/gruff/dataframe.rb +13 -15
  50. data/lib/daru/plotting/nyaplot/category.rb +1 -1
  51. data/lib/daru/plotting/nyaplot/dataframe.rb +15 -4
  52. data/lib/daru/plotting/nyaplot/vector.rb +1 -2
  53. data/lib/daru/vector.rb +308 -96
  54. data/lib/daru/version.rb +1 -1
  55. data/profile/vector_new.rb +9 -0
  56. data/spec/accessors/gsl_wrapper_spec.rb +38 -35
  57. data/spec/accessors/nmatrix_wrapper_spec.rb +25 -22
  58. data/spec/category_spec.rb +24 -20
  59. data/spec/core/group_by_spec.rb +238 -4
  60. data/spec/core/merge_spec.rb +1 -1
  61. data/spec/core/query_spec.rb +65 -50
  62. data/spec/daru_spec.rb +22 -0
  63. data/spec/dataframe_spec.rb +473 -16
  64. data/spec/date_time/date_time_index_helper_spec.rb +72 -0
  65. data/spec/date_time/index_spec.rb +34 -16
  66. data/spec/date_time/offsets_spec.rb +14 -0
  67. data/spec/extensions/rserve_spec.rb +1 -1
  68. data/spec/extensions/which_dsl_spec.rb +38 -0
  69. data/spec/fixtures/boolean_converter_test.csv +5 -0
  70. data/spec/fixtures/duplicates.csv +32 -0
  71. data/spec/fixtures/eciresults.html +394 -0
  72. data/spec/fixtures/empty_rows_test.csv +17 -0
  73. data/spec/fixtures/macau.html +3691 -0
  74. data/spec/fixtures/macd_data.csv +150 -0
  75. data/spec/fixtures/matrix_test.csv +55 -55
  76. data/spec/fixtures/moneycontrol.html +6812 -0
  77. data/spec/fixtures/string_converter_test.csv +5 -0
  78. data/spec/fixtures/test_xls.xls +0 -0
  79. data/spec/fixtures/test_xls_2.xls +0 -0
  80. data/spec/fixtures/url_test.txt~ +0 -0
  81. data/spec/fixtures/valid_markup.html +62 -0
  82. data/spec/fixtures/wiki_climate.html +1243 -0
  83. data/spec/fixtures/wiki_table_info.html +631 -0
  84. data/spec/formatters/table_formatter_spec.rb +29 -0
  85. data/spec/index/categorical_index_spec.rb +33 -33
  86. data/spec/index/index_spec.rb +160 -41
  87. data/spec/index/multi_index_spec.rb +143 -33
  88. data/spec/io/io_spec.rb +246 -2
  89. data/spec/io/sql_data_source_spec.rb +31 -41
  90. data/spec/iruby/dataframe_spec.rb +17 -19
  91. data/spec/iruby/vector_spec.rb +26 -28
  92. data/spec/maths/arithmetic/dataframe_spec.rb +1 -1
  93. data/spec/maths/arithmetic/vector_spec.rb +18 -0
  94. data/spec/maths/statistics/vector_spec.rb +153 -15
  95. data/spec/plotting/gruff/category_spec.rb +3 -3
  96. data/spec/plotting/gruff/dataframe_spec.rb +14 -4
  97. data/spec/plotting/gruff/vector_spec.rb +9 -9
  98. data/spec/plotting/nyaplot/category_spec.rb +5 -9
  99. data/spec/plotting/nyaplot/dataframe_spec.rb +95 -47
  100. data/spec/plotting/nyaplot/vector_spec.rb +5 -11
  101. data/spec/shared/vector_display_spec.rb +12 -14
  102. data/spec/spec_helper.rb +30 -7
  103. data/spec/support/matchers.rb +5 -0
  104. data/spec/vector_spec.rb +306 -72
  105. metadata +96 -55
  106. data/spec/fixtures/stock_data.csv +0 -500
@@ -10,7 +10,7 @@ describe Daru::Vector, 'plotting category vector with gruff' do
10
10
  expect(plot).to receive :data
11
11
  dv.plot type: :bar
12
12
  end
13
-
13
+
14
14
  it 'plots bar graph with block' do
15
15
  expect(plot).to receive :labels=
16
16
  expect(plot).to receive :data
@@ -18,7 +18,7 @@ describe Daru::Vector, 'plotting category vector with gruff' do
18
18
  dv.plot(type: :bar) { |p| p.title = 'hello' }
19
19
  end
20
20
  end
21
-
21
+
22
22
  context 'pie' do
23
23
  let(:plot) { instance_double 'Gruff::Pie' }
24
24
  before { allow(Gruff::Pie).to receive(:new).and_return(plot) }
@@ -27,7 +27,7 @@ describe Daru::Vector, 'plotting category vector with gruff' do
27
27
  dv.plot type: :pie
28
28
  end
29
29
  end
30
-
30
+
31
31
  context 'sidebar' do
32
32
  let(:plot) { instance_double 'Gruff::SideBar' }
33
33
  before { allow(Gruff::SideBar).to receive(:new).and_return(plot) }
@@ -18,7 +18,7 @@ describe Daru::DataFrame, 'plotting dataframe using gruff' do
18
18
  expect(plot).to receive(:data).exactly(3).times
19
19
  df.plot type: :bar
20
20
  end
21
-
21
+
22
22
  it 'plots bar graph with block' do
23
23
  expect(plot).to receive :labels=
24
24
  expect(plot).to receive(:data).exactly(3).times
@@ -56,7 +56,7 @@ describe Daru::DataFrame, 'plotting dataframe using gruff' do
56
56
  df.plot type: :scatter, x: :c, y: :a
57
57
  end
58
58
  end
59
-
59
+
60
60
  context 'invalid type' do
61
61
  it { expect { df.plot type: :lol }.to raise_error ArgumentError }
62
62
  end
@@ -72,13 +72,23 @@ describe Daru::DataFrame, 'dataframe category plotting with gruff' do
72
72
  }, index: 'a'..'f')
73
73
  end
74
74
  before { df.to_category :c }
75
-
75
+
76
76
  context 'scatter' do
77
77
  let(:plot) { instance_double 'Gruff::Scatter' }
78
- before { allow(Gruff::Scatter).to receive(:new).and_return(plot) }
78
+ before { allow(Gruff::Scatter).to receive(:new).and_return(plot) }
79
79
  it 'plots scatter plot categorized by category vector' do
80
80
  expect(plot).to receive(:data).exactly(2).times
81
81
  df.plot type: :scatter, x: :a, y: :b, categorized: { by: :c }
82
82
  end
83
+
84
+ it 'plots with axes description' do
85
+ expect(plot).to receive(:data).exactly(2).times
86
+ expect(plot).to receive(:x_axis_label=).exactly(1).times
87
+ expect(plot).to receive(:y_axis_label=).exactly(1).times
88
+ df.plot type: :scatter, x: :a, y: :b, categorized: { by: :c } do |gruff_plot|
89
+ gruff_plot.x_axis_label = 'A data'
90
+ gruff_plot.y_axis_label = 'B data'
91
+ end
92
+ end
83
93
  end
84
94
  end
@@ -7,13 +7,13 @@ describe Daru::Vector, 'plotting vector with gruff' do
7
7
  context 'line' do
8
8
  let(:plot) { instance_double 'Gruff::Line' }
9
9
  before { allow(Gruff::Line).to receive(:new).and_return(plot) }
10
-
10
+
11
11
  it 'plots line graph without block' do
12
12
  expect(plot).to receive(:labels=)
13
13
  expect(plot).to receive(:data)
14
14
  dv.plot type: :line
15
15
  end
16
-
16
+
17
17
  it 'plots line graph with block' do
18
18
  expect(plot).to receive :labels=
19
19
  expect(plot).to receive :data
@@ -21,28 +21,28 @@ describe Daru::Vector, 'plotting vector with gruff' do
21
21
  dv.plot(type: :line) { |p| p.title = 'hello' }
22
22
  end
23
23
  end
24
-
24
+
25
25
  context 'bar' do
26
26
  let(:plot) { instance_double 'Gruff::Bar' }
27
27
  before { allow(Gruff::Bar).to receive(:new).and_return(plot) }
28
-
28
+
29
29
  it 'plots bar graph' do
30
30
  expect(plot).to receive :labels=
31
31
  expect(plot).to receive :data
32
32
  dv.plot type: :bar
33
33
  end
34
34
  end
35
-
35
+
36
36
  context 'pie' do
37
37
  let(:plot) { instance_double 'Gruff::Pie' }
38
38
  before { allow(Gruff::Pie).to receive(:new).and_return(plot) }
39
-
39
+
40
40
  it 'plots pie graph' do
41
41
  expect(plot).to receive(:data).exactly(3).times
42
42
  dv.plot type: :pie
43
43
  end
44
44
  end
45
-
45
+
46
46
  context 'scatter' do
47
47
  let(:plot) { instance_double 'Gruff::Scatter' }
48
48
  before { allow(Gruff::Scatter).to receive(:new).and_return(plot) }
@@ -52,7 +52,7 @@ describe Daru::Vector, 'plotting vector with gruff' do
52
52
  dv.plot type: :scatter
53
53
  end
54
54
  end
55
-
55
+
56
56
  context 'sidebar' do
57
57
  let(:plot) { instance_double 'Gruff::SideBar' }
58
58
  before { allow(Gruff::SideBar).to receive(:new).and_return(plot) }
@@ -63,7 +63,7 @@ describe Daru::Vector, 'plotting vector with gruff' do
63
63
  dv.plot type: :sidebar
64
64
  end
65
65
  end
66
-
66
+
67
67
  context 'invalid type' do
68
68
  it { expect { dv.plot type: :lol }.to raise_error ArgumentError }
69
69
  end
@@ -7,7 +7,7 @@ describe Daru::Vector, 'plotting category' do
7
7
  Daru::Vector.new ['III']*10 + ['II']*5 + ['I']*5,
8
8
  type: :category,
9
9
  categories: ['I', 'II', 'III']
10
- end
10
+ end
11
11
  before do
12
12
  Daru.plotting_library = :nyaplot
13
13
  allow(Nyaplot::Plot).to receive(:new).and_return(plot)
@@ -17,7 +17,6 @@ describe Daru::Vector, 'plotting category' do
17
17
  expect(plot).to receive(:add).with(:bar, ['I', 'II', 'III'], [5, 5, 10])
18
18
  expect(plot).to receive :x_label
19
19
  expect(plot).to receive :y_label
20
- expect(plot).to receive(:show)
21
20
  dv.plot(type: :bar) do |p|
22
21
  p.x_label 'Categories'
23
22
  p.y_label 'Frequency'
@@ -26,23 +25,20 @@ describe Daru::Vector, 'plotting category' do
26
25
 
27
26
  it 'plots bar graph without taking a block' do
28
27
  expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [5, 5, 10])
29
- expect(plot).to receive(:show)
30
- dv.plot(type: :bar)
28
+ expect(dv.plot(type: :bar)).to eq plot
31
29
  end
32
30
 
33
31
  it 'plots bar graph with percentage' do
34
32
  expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [25, 25, 50])
35
33
  expect(plot).to receive(:yrange).with [0, 100]
36
- expect(plot).to receive(:show)
37
- dv.plot(type: :bar, method: :percentage)
34
+ expect(dv.plot(type: :bar, method: :percentage)).to eq plot
38
35
  end
39
36
 
40
37
  it 'plots bar graph with fraction' do
41
38
  expect(plot).to receive(:add).with(:bar, ["I", "II", "III"], [0.25, 0.25, 0.50])
42
39
  expect(plot).to receive(:yrange).with [0, 1]
43
- expect(plot).to receive(:show)
44
- dv.plot(type: :bar, method: :fraction)
45
- end
40
+ expect(dv.plot(type: :bar, method: :fraction)).to eq plot
41
+ end
46
42
  end
47
43
 
48
44
  context 'other type' do
@@ -21,6 +21,16 @@ describe Daru::DataFrame, 'plotting' do
21
21
  index: [:one, :two, :three, :four]
22
22
  )
23
23
  }
24
+
25
+ let(:df_with_index_as_default) {
26
+ Nyaplot::DataFrame.new [
27
+ {:x=>1, :y1=>5, :y2=>-3, :cat=>:a, :_index=>:one},
28
+ {:x=>2, :y1=>7, :y2=>-7, :cat=>:b, :_index=>:two},
29
+ {:x=>3, :y1=>9, :y2=>-11, :cat=>:c, :_index=>:three},
30
+ {:x=>4, :y1=>11, :y2=>-15, :cat=>:d, :_index=>:four}
31
+ ]
32
+ }
33
+
24
34
  let(:plot) { instance_double('Nyaplot::Plot') }
25
35
  let(:diagram) { instance_double('Nyaplot::Diagram') }
26
36
 
@@ -35,8 +45,7 @@ describe Daru::DataFrame, 'plotting' do
35
45
  .with(numerics.to_nyaplotdf, :box, :x, :y1, :y2)
36
46
  .ordered
37
47
 
38
- expect(plot).to receive(:show).ordered
39
- data_frame.plot(type: :box)
48
+ expect(data_frame.plot(type: :box)).to eq plot
40
49
  end
41
50
  end
42
51
 
@@ -47,8 +56,7 @@ describe Daru::DataFrame, 'plotting' do
47
56
  .with(data_frame.to_nyaplotdf, :scatter, :x, :y1)
48
57
  .ordered
49
58
 
50
- expect(plot).to receive(:show).ordered
51
- data_frame.plot(type: :scatter, x: :x, y: :y1)
59
+ expect(data_frame.plot(type: :scatter, x: :x, y: :y1)).to eq plot
52
60
  end
53
61
 
54
62
  it 'works without :y provided' do
@@ -56,8 +64,20 @@ describe Daru::DataFrame, 'plotting' do
56
64
  .with(data_frame.to_nyaplotdf, :scatter, :x)
57
65
  .ordered
58
66
 
59
- expect(plot).to receive(:show).ordered
60
- data_frame.plot(type: :scatter, x: :x)
67
+ expect(data_frame.plot(type: :scatter, x: :x)).to eq plot
68
+ end
69
+ end
70
+
71
+ context 'default x axis' do
72
+ it 'sets the x axis as the index value if not defined' do
73
+ expect(plot).to receive(:add_with_df)
74
+ .with(df_with_index_as_default, :line, :_index, :y1)
75
+ .ordered
76
+
77
+ expect(
78
+ data_frame.plot(
79
+ type: :line, y: :y1)
80
+ ).to eq plot
61
81
  end
62
82
  end
63
83
 
@@ -69,9 +89,10 @@ describe Daru::DataFrame, 'plotting' do
69
89
  expect(plot).to receive(:add_with_df)
70
90
  .with(data_frame.to_nyaplotdf, :scatter, :x, :y2)
71
91
  .ordered
72
- expect(plot).to receive(:show).ordered
73
92
 
74
- data_frame.plot(type: :scatter, x: [:x, :x], y: [:y1, :y2])
93
+ expect(
94
+ data_frame.plot(type: :scatter, x: [:x, :x], y: [:y1, :y2])
95
+ ).to eq plot
75
96
  end
76
97
 
77
98
  it 'works with multiple types provided' do
@@ -81,9 +102,11 @@ describe Daru::DataFrame, 'plotting' do
81
102
  expect(plot).to receive(:add_with_df)
82
103
  .with(data_frame.to_nyaplotdf, :line, :x, :y2)
83
104
  .ordered
84
- expect(plot).to receive(:show).ordered
85
105
 
86
- data_frame.plot(type: [:scatter, :line], x: [:x, :x], y: [:y1, :y2])
106
+ expect(
107
+ data_frame.plot(
108
+ type: [:scatter, :line], x: [:x, :x], y: [:y1, :y2])
109
+ ).to eq plot
87
110
  end
88
111
 
89
112
  it 'works with numeric var names' do
@@ -93,9 +116,9 @@ describe Daru::DataFrame, 'plotting' do
93
116
  expect(plot).to receive(:add_with_df)
94
117
  .with(data_frame.to_nyaplotdf, :line, :x, :y2)
95
118
  .ordered
96
- expect(plot).to receive(:show).ordered
97
119
 
98
- data_frame.plot(
120
+ expect(
121
+ data_frame.plot(
99
122
  type: [:scatter, :line],
100
123
  # FIXME: this didn't work due to default type: :scatter opts
101
124
  #type1: :scatter,
@@ -104,7 +127,8 @@ describe Daru::DataFrame, 'plotting' do
104
127
  x2: :x,
105
128
  y1: :y1,
106
129
  y2: :y2
107
- )
130
+ )
131
+ ).to eq plot
108
132
  end
109
133
  end
110
134
  end
@@ -121,13 +145,13 @@ describe Daru::DataFrame, 'category plotting' do
121
145
  end
122
146
  let(:plot) { instance_double('Nyaplot::Plot') }
123
147
  let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
124
-
148
+
125
149
  before do
126
150
  df.to_category :c
127
151
  allow(Nyaplot::Plot).to receive(:new).and_return(plot)
128
152
  allow(plot).to receive(:add_with_df).and_return(diagram)
129
153
  end
130
-
154
+
131
155
  it 'plots scatter plot categoried by color with a block' do
132
156
  expect(plot).to receive :add_with_df
133
157
  expect(diagram).to receive(:title).exactly(3).times
@@ -136,7 +160,6 @@ describe Daru::DataFrame, 'category plotting' do
136
160
  expect(plot).to receive :legend
137
161
  expect(plot).to receive :xrange
138
162
  expect(plot).to receive :yrange
139
- expect(plot).to receive :show
140
163
  df.plot(type: :scatter, x: :a, y: :b, categorized: {by: :c, method: :color}) do |p, d|
141
164
  p.xrange [-10, 10]
142
165
  p.yrange [-10, 10]
@@ -149,9 +172,11 @@ describe Daru::DataFrame, 'category plotting' do
149
172
  expect(diagram).to receive(:color).exactly(3).times
150
173
  expect(diagram).to receive(:tooltip_contents).exactly(3).times
151
174
  expect(plot).to receive :legend
152
- expect(plot).to receive :show
153
- df.plot(type: :scatter, x: :a, y: :b,
154
- categorized: {by: :c, method: :color})
175
+ expect(
176
+ df.plot(
177
+ type: :scatter, x: :a, y: :b,
178
+ categorized: {by: :c, method: :color})
179
+ ).to eq plot
155
180
  end
156
181
 
157
182
  it 'plots scatter plot categoried by custom colors' do
@@ -162,9 +187,8 @@ describe Daru::DataFrame, 'category plotting' do
162
187
  expect(diagram).to receive(:color).with :green
163
188
  expect(diagram).to receive(:tooltip_contents).exactly(3).times
164
189
  expect(plot).to receive :legend
165
- expect(plot).to receive :show
166
- df.plot(type: :scatter, x: :a, y: :b,
167
- categorized: {by: :c, method: :color, color: [:red, :blue, :green]})
190
+ expect(df.plot(type: :scatter, x: :a, y: :b,
191
+ categorized: {by: :c, method: :color, color: [:red, :blue, :green]})).to eq plot
168
192
  end
169
193
 
170
194
  it 'plots scatter plot categoried by shape' do
@@ -173,9 +197,8 @@ describe Daru::DataFrame, 'category plotting' do
173
197
  expect(diagram).to receive(:shape).exactly(3).times
174
198
  expect(diagram).to receive(:tooltip_contents).exactly(3).times
175
199
  expect(plot).to receive :legend
176
- expect(plot).to receive :show
177
- df.plot(type: :scatter, x: :a, y: :b,
178
- categorized: {by: :c, method: :shape})
200
+ expect(df.plot(type: :scatter, x: :a, y: :b,
201
+ categorized: {by: :c, method: :shape})).to eq plot
179
202
  end
180
203
 
181
204
  it 'plots scatter plot categoried by custom shapes' do
@@ -186,9 +209,13 @@ describe Daru::DataFrame, 'category plotting' do
186
209
  expect(diagram).to receive(:shape).with 'diamond'
187
210
  expect(diagram).to receive(:tooltip_contents).exactly(3).times
188
211
  expect(plot).to receive :legend
189
- expect(plot).to receive :show
190
- df.plot(type: :scatter, x: :a, y: :b,
191
- categorized: {by: :c, method: :shape, shape: %w(circle triangle-up diamond)})
212
+ expect(
213
+ df.plot(
214
+ type: :scatter, x: :a, y: :b,
215
+ categorized: {
216
+ by: :c, method: :shape,
217
+ shape: %w(circle triangle-up diamond)})
218
+ ).to eq plot
192
219
  end
193
220
 
194
221
  it 'plots scatter plot categoried by size' do
@@ -197,9 +224,8 @@ describe Daru::DataFrame, 'category plotting' do
197
224
  expect(diagram).to receive(:size).exactly(3).times
198
225
  expect(diagram).to receive(:tooltip_contents).exactly(3).times
199
226
  expect(plot).to receive :legend
200
- expect(plot).to receive :show
201
- df.plot(type: :scatter, x: :a, y: :b,
202
- categorized: {by: :c, method: :size})
227
+ expect(df.plot(type: :scatter, x: :a, y: :b,
228
+ categorized: {by: :c, method: :size})).to eq plot
203
229
  end
204
230
 
205
231
  it 'plots scatter plot categoried by cusom sizes' do
@@ -210,9 +236,17 @@ describe Daru::DataFrame, 'category plotting' do
210
236
  expect(diagram).to receive(:size).with 300
211
237
  expect(diagram).to receive(:tooltip_contents).exactly(3).times
212
238
  expect(plot).to receive :legend
213
- expect(plot).to receive :show
214
- df.plot(type: :scatter, x: :a, y: :b,
215
- categorized: {by: :c, method: :size, size: [100, 200, 300]})
239
+ expect(
240
+ df.plot(
241
+ type: :scatter,
242
+ x: :a, y: :b,
243
+ categorized: {
244
+ by: :c,
245
+ method: :size,
246
+ size: [100, 200, 300]
247
+ }
248
+ )
249
+ ).to eq plot
216
250
  end
217
251
  end
218
252
 
@@ -226,13 +260,13 @@ describe Daru::DataFrame, 'category plotting' do
226
260
  end
227
261
  let(:plot) { instance_double('Nyaplot::Plot') }
228
262
  let(:diagram) { instance_double('Nyaplot::Diagram::Scatter') }
229
-
263
+
230
264
  before do
231
265
  df.to_category :c
232
266
  allow(Nyaplot::Plot).to receive(:new).and_return(plot)
233
267
  allow(plot).to receive(:add_with_df).and_return(diagram)
234
268
  end
235
-
269
+
236
270
  it 'plots line plot categoried by color with a block' do
237
271
  expect(plot).to receive :add_with_df
238
272
  expect(diagram).to receive(:title).exactly(3).times
@@ -240,7 +274,6 @@ describe Daru::DataFrame, 'category plotting' do
240
274
  expect(plot).to receive :legend
241
275
  expect(plot).to receive :xrange
242
276
  expect(plot).to receive :yrange
243
- expect(plot).to receive :show
244
277
  df.plot(type: :line, x: :a, y: :b, categorized: {by: :c, method: :color}) do |p, d|
245
278
  p.xrange [-10, 10]
246
279
  p.yrange [-10, 10]
@@ -252,8 +285,12 @@ describe Daru::DataFrame, 'category plotting' do
252
285
  expect(diagram).to receive(:title).exactly(3).times
253
286
  expect(diagram).to receive(:color).exactly(3).times
254
287
  expect(plot).to receive :legend
255
- expect(plot).to receive :show
256
- df.plot(type: :line, x: :a, y: :b, categorized: {by: :c, method: :color})
288
+ expect(
289
+ df.plot(
290
+ type: :line, x: :a, y: :b,
291
+ categorized: {by: :c, method: :color}
292
+ )
293
+ ).to eq plot
257
294
  end
258
295
 
259
296
  it 'plots line plot categoried by custom colors' do
@@ -263,9 +300,12 @@ describe Daru::DataFrame, 'category plotting' do
263
300
  expect(diagram).to receive(:color).with :blue
264
301
  expect(diagram).to receive(:color).with :green
265
302
  expect(plot).to receive :legend
266
- expect(plot).to receive :show
267
- df.plot(type: :line, x: :a, y: :b,
268
- categorized: {by: :c, method: :color, color: [:red, :blue, :green]})
303
+ expect(
304
+ df.plot(
305
+ type: :line, x: :a, y: :b,
306
+ categorized: {by: :c, method: :color, color: [:red, :blue, :green]}
307
+ )
308
+ ).to eq plot
269
309
  end
270
310
 
271
311
  it 'plots line plot categoried by stroke width' do
@@ -273,8 +313,12 @@ describe Daru::DataFrame, 'category plotting' do
273
313
  expect(diagram).to receive(:title).exactly(3).times
274
314
  expect(diagram).to receive(:stroke_width).exactly(3).times
275
315
  expect(plot).to receive :legend
276
- expect(plot).to receive :show
277
- df.plot(type: :line, x: :a, y: :b, categorized: {by: :c, method: :stroke_width})
316
+ expect(
317
+ df.plot(
318
+ type: :line, x: :a, y: :b,
319
+ categorized: {by: :c, method: :stroke_width}
320
+ )
321
+ ).to eq plot
278
322
  end
279
323
 
280
324
  it 'plots line plot categoried by custom stroke widths' do
@@ -284,9 +328,13 @@ describe Daru::DataFrame, 'category plotting' do
284
328
  expect(diagram).to receive(:stroke_width).with 200
285
329
  expect(diagram).to receive(:stroke_width).with 300
286
330
  expect(plot).to receive :legend
287
- expect(plot).to receive :show
288
- df.plot(type: :line, x: :a, y: :b,
289
- categorized: {by: :c, method: :stroke_width, stroke_width: [100, 200, 300]})
331
+ expect(
332
+ df.plot(
333
+ type: :line, x: :a, y: :b,
334
+ categorized: {
335
+ by: :c, method: :stroke_width, stroke_width: [100, 200, 300]}
336
+ )
337
+ ).to eq plot
290
338
  end
291
339
  end
292
340