quandl_format 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/UPGRADE.md +6 -0
- data/lib/quandl/error/column_count_mismatch.rb +1 -1
- data/lib/quandl/format/dataset/attributes.rb +5 -5
- data/lib/quandl/format/dataset/load.rb +28 -13
- data/lib/quandl/format/version.rb +1 -1
- data/spec/fixtures/data/missing_dashes.qdf +21 -0
- data/spec/lib/quandl/format/dataset/errors_spec.rb +2 -39
- data/spec/lib/quandl/format/dataset/valid_data_spec.rb +43 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d570d30030c6efc98ca36991c9f7bd696ef1b06
|
4
|
+
data.tar.gz: a3055d3a66e3189abdee26cc3cd30454c78919aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65deb544f8ff59f3cb623cfa0672319c48b39a5243e20837d196ce8057eb3523a7908d4bbd801a14b796de6d47ba88a7c09e82c97a507357774018c7b6a92d1a
|
7
|
+
data.tar.gz: cd66e027d2cbfa58b0e6e23b1b1369891101053715fe046de229c4202f8ac5a39d6737629a4954d97eba5bf1d23f217345cc4a071b30cfeafb4ed896416dcab9
|
data/UPGRADE.md
CHANGED
@@ -103,17 +103,17 @@ module Attributes
|
|
103
103
|
private
|
104
104
|
|
105
105
|
def raise_row_column_mismatch!(row, index)
|
106
|
-
m = "
|
107
|
-
raise Quandl::Error::ColumnCountMismatch, m
|
106
|
+
m = "Unexpected number of points in this row '#{row}'. Expected #{data[0].count} but found #{row.count} based on #{data[0]}"
|
107
|
+
raise Quandl::Error::ColumnCountMismatch.new( row: row, line: index, context: 'data_rows_should_have_equal_columns!' ), m
|
108
108
|
end
|
109
109
|
|
110
110
|
def raise_column_count_mismatch!(row, index)
|
111
|
-
m = "
|
112
|
-
raise Quandl::Error::ColumnCountMismatch, m
|
111
|
+
m = "Unexpected number of points in this row '#{row}'. Expected #{column_names.count} but found #{row.count} based on #{column_names}"
|
112
|
+
raise Quandl::Error::ColumnCountMismatch.new( row: row, line: index+1, context: 'data_row_count_should_match_column_count!' ), m
|
113
113
|
end
|
114
114
|
|
115
115
|
def raise_unknown_attribute_error!(key)
|
116
|
-
m = "
|
116
|
+
m = "Unknown Field '#{key}' valid fields are: #{self.class.attribute_names.join(', ')}"
|
117
117
|
raise Quandl::Error::UnknownAttribute, m
|
118
118
|
end
|
119
119
|
|
@@ -38,8 +38,9 @@ class Quandl::Format::Dataset::Load
|
|
38
38
|
section_type = :attributes
|
39
39
|
|
40
40
|
# have we reached the end of the attributes?
|
41
|
-
elsif line
|
41
|
+
elsif line == '-'
|
42
42
|
# update the section to data
|
43
|
+
nodes[-1][:data_line] = line_index + 1
|
43
44
|
section_type = :data
|
44
45
|
# skip to the next line
|
45
46
|
next
|
@@ -77,31 +78,45 @@ class Quandl::Format::Dataset::Load
|
|
77
78
|
|
78
79
|
def parse_yaml_attributes(node)
|
79
80
|
YAML.load( node[:attributes] ).symbolize_keys!
|
80
|
-
rescue =>
|
81
|
-
|
82
|
-
message += "#{$!}\n"
|
83
|
-
message += "--"
|
84
|
-
Quandl::Logger.error(message)
|
81
|
+
rescue => err
|
82
|
+
log_yaml_parse_error(node, err)
|
85
83
|
nil
|
86
84
|
end
|
87
85
|
|
88
86
|
def node_to_dataset(node)
|
89
87
|
Quandl::Format::Dataset.new( node[:attributes] )
|
90
|
-
rescue =>
|
88
|
+
rescue => err
|
89
|
+
log_dataset_error(node, err)
|
90
|
+
end
|
91
|
+
|
92
|
+
def attribute_format
|
93
|
+
/^([a-z0-9_]+): (.+)/
|
94
|
+
end
|
95
|
+
|
96
|
+
def log_yaml_parse_error(node, err)
|
97
|
+
message = "Attribute parse error at line #{ node[:line] + err.line } column #{err.column}. #{err.problem} (#{err.class})\n"
|
98
|
+
message += "Did you forget to delimit the meta data section from the data section with a one or more dashes ('-')?\n" unless node[:attributes] =~ /^-/
|
99
|
+
message += "--"
|
100
|
+
Quandl::Logger.error(message)
|
101
|
+
end
|
102
|
+
|
103
|
+
def log_dataset_error( node, err )
|
91
104
|
message = ''
|
92
105
|
message += node[:attributes][:source_code] + '/' if node[:attributes][:source_code].present?
|
93
106
|
message += node[:attributes][:code] + ' '
|
94
|
-
|
95
|
-
|
107
|
+
# include specific line if available
|
108
|
+
if err.respond_to?(:line)
|
109
|
+
message += "error at line #{node[:data_line].to_i + err.line.to_i}\n"
|
110
|
+
else
|
111
|
+
message += "error around line #{node[:line]}\n"
|
112
|
+
end
|
113
|
+
# include original error
|
114
|
+
message += "#{$!} (#{err.class})\n"
|
96
115
|
message += "--"
|
97
116
|
Quandl::Logger.error(message)
|
98
117
|
nil
|
99
118
|
end
|
100
119
|
|
101
|
-
def attribute_format
|
102
|
-
/^([a-z0-9_]+): (.+)/
|
103
|
-
end
|
104
|
-
|
105
120
|
end
|
106
121
|
|
107
122
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
code: "BLAKE_TEST_1"
|
2
|
+
name: "A new title"
|
3
|
+
description: "The description Date, Open, High"
|
4
|
+
private: false
|
5
|
+
Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
|
6
|
+
2013-11-22,1252.0,454.95,448.2,450.0,450.0,1354405.0,6099.41
|
7
|
+
2013-11-21,452.25,457.75,449.1,451.2,451.0,218881.0,992.94
|
8
|
+
|
9
|
+
code: "BLAKE_TEST_2"
|
10
|
+
name: "A new title"
|
11
|
+
description: "The description Date, Open, High"
|
12
|
+
Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
|
13
|
+
2013-11-22,1252.0,454.95,448.2,450.0,450.0,1354405.0,6099.41
|
14
|
+
2013-11-21,452.25,457.75,449.1,451.2,451.0,218881.0,992.94
|
15
|
+
|
16
|
+
code: "BLAKE_TEST_3"
|
17
|
+
name: "A new title"
|
18
|
+
description: "The description Date, Open, High"
|
19
|
+
Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
|
20
|
+
2013-11-22,1252.0,454.95,448.2,450.0,450.0,1354405.0,6099.41
|
21
|
+
2013-11-21,452.25,457.75,449.1,451.2,451.0,218881.0,992.94
|
@@ -2,51 +2,14 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Quandl::Format::Dataset do
|
5
|
-
subject{ data }
|
6
|
-
|
7
|
-
context "valid.qdf" do
|
8
|
-
let(:data){ Quandl::Format::Dataset.load( fixtures_data['valid'] ) }
|
9
|
-
|
10
|
-
it{ should be_a Array }
|
11
|
-
its(:count){ should eq 3 }
|
12
|
-
|
13
|
-
describe "#first" do
|
14
|
-
subject{ data.first }
|
15
|
-
its(:code){ should eq 'BLAKE_TEST_1' }
|
16
|
-
its(:name){ should eq 'A new title' }
|
17
|
-
its(:description){ should eq 'The description Date, Open, High'}
|
18
|
-
its(:column_names){ should eq ['Date','Open','High','Low','Last','Close','Total Trade Quantity','Turnover (Lacs)']}
|
19
|
-
its(:data){ should eq Quandl::Data.new([['2013-11-22','1252.0','454.95','448.2','450.0','450.0','1354405.0','6099.41'],['2013-11-21','452.25','457.75','449.1','451.2','451.0','218881.0','992.94']]) }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "annual.qdf" do
|
24
|
-
let(:data){ Quandl::Format::Dataset.load( fixtures_data['annual'] ) }
|
25
|
-
|
26
|
-
it{ should be_a Array }
|
27
|
-
its(:count){ should eq 1 }
|
28
|
-
|
29
|
-
describe "#first" do
|
30
|
-
subject{ data.first }
|
31
|
-
its(:code){ should eq 'ANNUAL_DATA' }
|
32
|
-
its(:name){ should eq 'A new title' }
|
33
|
-
its(:description){ should eq 'Annual Data'}
|
34
|
-
its(:column_names){ should eq ['Date','Open','High']}
|
35
|
-
its(:data){ should eq [
|
36
|
-
[ Date.parse('2013-12-31'), 1252.0, 454.95 ],
|
37
|
-
[ Date.parse('2012-12-31'), 452.25, 457.75 ],
|
38
|
-
[ Date.parse('2011-12-31'), 452.25, 457.75 ],
|
39
|
-
[ Date.parse('2010-12-31'), 452.25, 457.75 ],
|
40
|
-
]}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
5
|
expected_errors = [
|
45
6
|
{ file: 'invalid_data', error: /Date/ },
|
46
7
|
{ file: 'unknown_attribute', error: /this_attribute_does_not_exist/ },
|
47
8
|
{ file: 'mismatched_columns', error: /column_names had 4 columns/ },
|
48
9
|
{ file: 'mismatched_rows', error: /had 3 columns/ },
|
49
10
|
{ file: 'invalid_yaml', error: /could not find expected ':'/ },
|
11
|
+
{ file: 'missing_dashes', error: /Attribute parse error at line 6 column 1/ },
|
12
|
+
{ file: 'missing_dashes', error: /Data delimiter '-' is missing/ },
|
50
13
|
]
|
51
14
|
# run each expectation
|
52
15
|
expected_errors.each do |pair|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Quandl::Format::Dataset do
|
4
|
+
subject{ data }
|
5
|
+
|
6
|
+
context "valid.qdf" do
|
7
|
+
let(:data){ Quandl::Format::Dataset.load( fixtures_data['valid'] ) }
|
8
|
+
|
9
|
+
it{ should be_a Array }
|
10
|
+
its(:count){ should eq 3 }
|
11
|
+
|
12
|
+
describe "#first" do
|
13
|
+
subject{ data.first }
|
14
|
+
its(:code){ should eq 'BLAKE_TEST_1' }
|
15
|
+
its(:name){ should eq 'A new title' }
|
16
|
+
its(:description){ should eq 'The description Date, Open, High'}
|
17
|
+
its(:column_names){ should eq ['Date','Open','High','Low','Last','Close','Total Trade Quantity','Turnover (Lacs)']}
|
18
|
+
its(:data){ should eq Quandl::Data.new([['2013-11-22','1252.0','454.95','448.2','450.0','450.0','1354405.0','6099.41'],['2013-11-21','452.25','457.75','449.1','451.2','451.0','218881.0','992.94']]) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "annual.qdf" do
|
23
|
+
let(:data){ Quandl::Format::Dataset.load( fixtures_data['annual'] ) }
|
24
|
+
|
25
|
+
it{ should be_a Array }
|
26
|
+
its(:count){ should eq 1 }
|
27
|
+
|
28
|
+
describe "#first" do
|
29
|
+
subject{ data.first }
|
30
|
+
its(:code){ should eq 'ANNUAL_DATA' }
|
31
|
+
its(:name){ should eq 'A new title' }
|
32
|
+
its(:description){ should eq 'Annual Data'}
|
33
|
+
its(:column_names){ should eq ['Date','Open','High']}
|
34
|
+
its(:data){ should eq [
|
35
|
+
[ Date.parse('2013-12-31'), 1252.0, 454.95 ],
|
36
|
+
[ Date.parse('2012-12-31'), 452.25, 457.75 ],
|
37
|
+
[ Date.parse('2011-12-31'), 452.25, 457.75 ],
|
38
|
+
[ Date.parse('2010-12-31'), 452.25, 457.75 ],
|
39
|
+
]}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Hilscher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- spec/fixtures/data/invalid_yaml.qdf
|
170
170
|
- spec/fixtures/data/mismatched_columns.qdf
|
171
171
|
- spec/fixtures/data/mismatched_rows.qdf
|
172
|
+
- spec/fixtures/data/missing_dashes.qdf
|
172
173
|
- spec/fixtures/data/unknown_attribute.qdf
|
173
174
|
- spec/fixtures/data/valid.qdf
|
174
175
|
- spec/fixtures/format.rb
|
@@ -177,6 +178,7 @@ files:
|
|
177
178
|
- spec/lib/quandl/format/dataset/client_spec.rb
|
178
179
|
- spec/lib/quandl/format/dataset/errors_spec.rb
|
179
180
|
- spec/lib/quandl/format/dataset/load_spec.rb
|
181
|
+
- spec/lib/quandl/format/dataset/valid_data_spec.rb
|
180
182
|
- spec/lib/quandl/format/dataset_spec.rb
|
181
183
|
- spec/spec_helper.rb
|
182
184
|
homepage: http://blake.hilscher.ca/
|
@@ -211,6 +213,7 @@ test_files:
|
|
211
213
|
- spec/fixtures/data/invalid_yaml.qdf
|
212
214
|
- spec/fixtures/data/mismatched_columns.qdf
|
213
215
|
- spec/fixtures/data/mismatched_rows.qdf
|
216
|
+
- spec/fixtures/data/missing_dashes.qdf
|
214
217
|
- spec/fixtures/data/unknown_attribute.qdf
|
215
218
|
- spec/fixtures/data/valid.qdf
|
216
219
|
- spec/fixtures/format.rb
|
@@ -219,5 +222,6 @@ test_files:
|
|
219
222
|
- spec/lib/quandl/format/dataset/client_spec.rb
|
220
223
|
- spec/lib/quandl/format/dataset/errors_spec.rb
|
221
224
|
- spec/lib/quandl/format/dataset/load_spec.rb
|
225
|
+
- spec/lib/quandl/format/dataset/valid_data_spec.rb
|
222
226
|
- spec/lib/quandl/format/dataset_spec.rb
|
223
227
|
- spec/spec_helper.rb
|