quandl_format 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b474c3187e8739850c58e91360e3ab2b59340f2d
4
- data.tar.gz: e9b54e19bc1ec87383303bc285d60b42ca421f05
3
+ metadata.gz: 2c2355e2207291cd09c76a495b2565c28fefdbd0
4
+ data.tar.gz: 5699891dd773b8d58e4824d4a7411b39db054e92
5
5
  SHA512:
6
- metadata.gz: be6a15eff00055881aaff30529320a3c34c6337990ed0bf13e03cc85307bb3a52a82fddd8f3d7a84c8030dd1946611afe714df6a130f7614695b96edc0fec938
7
- data.tar.gz: 947092cce001ee7cfa1dd4c3c3505dd5a82007bf45150a134e015b95cc44172f661793b418cacbfb8364e4b62d2d9094eca1e4494a2b16e156763ef5b5191f4d
6
+ metadata.gz: 6426c47bc68a9891942a529ba2220a3360de14031e68f7b8d117a5faaf01cad4ba8e30c406b6c101778c09a6a33dddb7f04037ef26b5ceff4a4807f4b6e35606
7
+ data.tar.gz: a0db81d386ea365f37d2f64007c04f37ec6e4cb7f0fdb577905ae6824eaeded19545c675bf7ac20f52d2574d989e0613a7a7bcd8548598443a2e76ed0dc584e8
data/UPGRADE.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.8
2
+
3
+ * QUGC-57 validation at an inappropriate time; move validations to Quandl::Client
4
+ * more accurate error messages and line numbers
5
+
6
+
1
7
  ## 0.2.7
2
8
 
3
9
  * parsing junk string should fail gracefully
@@ -62,8 +62,6 @@ module Attributes
62
62
  rows = rows.to_table if rows.respond_to?(:to_table)
63
63
  @data = Quandl::Data.new(rows).to_date
64
64
  self.column_names = @data.headers if @data.headers.present?
65
- data_row_count_should_match_column_count!
66
- data_rows_should_have_equal_columns!
67
65
  @data
68
66
  end
69
67
 
@@ -86,38 +84,9 @@ module Attributes
86
84
  def attributes
87
85
  self.class.attribute_names.inject({}){|m,k| m[k] = self.send(k) unless self.send(k).nil?; m }
88
86
  end
89
-
90
- protected
91
-
92
- def data_rows_should_have_equal_columns!
93
- return if data.blank?
94
- row_count = data[0].count
95
- data.each_with_index do |row, index|
96
- raise_row_column_mismatch!(row, index) unless row.count == row_count
97
- end
98
- end
99
-
100
- def data_row_count_should_match_column_count!
101
- return if column_names.blank?
102
- column_count = column_names.count
103
- data.each_with_index do |row, index|
104
- raise_column_count_mismatch!(row, index) unless row.count == column_count
105
- end
106
- end
107
87
 
108
-
109
88
  private
110
89
 
111
- def raise_row_column_mismatch!(row, index)
112
- m = "Unexpected number of points in this row '#{row}'. Expected #{data[0].count} but found #{row.count} based on #{data[0]}"
113
- raise Quandl::Error::ColumnCountMismatch.new( row: row, line: index, context: 'data_rows_should_have_equal_columns!' ), m
114
- end
115
-
116
- def raise_column_count_mismatch!(row, index)
117
- m = "Unexpected number of points in this row '#{row}'. Expected #{column_names.count} but found #{row.count} based on #{column_names}"
118
- raise Quandl::Error::ColumnCountMismatch.new( row: row, line: index+1, context: 'data_row_count_should_match_column_count!' ), m
119
- end
120
-
121
90
  def raise_unknown_attribute_error!(key)
122
91
  m = "Unknown Field '#{key}' valid fields are: #{self.class.meta_attribute_names.join(', ')}"
123
92
  raise Quandl::Error::UnknownAttribute, m
@@ -19,7 +19,7 @@ class Quandl::Format::Dataset::Load
19
19
  # process line
20
20
  node = process_line(line, node, &block)
21
21
  end
22
- process_tail(node, &block)
22
+ process_tail(node, &block)
23
23
  end
24
24
 
25
25
  def file(path)
@@ -43,7 +43,7 @@ class Quandl::Format::Dataset::Load
43
43
  end
44
44
 
45
45
  def new_node(line=0)
46
- { line: line, section: :attributes, data: '', attributes: '', data_line: 0 }
46
+ { line: line, section: :attributes, data: '', attributes: '', data_line: 0, offset: line==0 ? 0 : line-1 }
47
47
  end
48
48
 
49
49
  def process_tail(node, &block)
@@ -58,7 +58,10 @@ class Quandl::Format::Dataset::Load
58
58
  # strip whitespace
59
59
  line = rline.strip.rstrip
60
60
  # skip comments and blank lines
61
- return node if line[0] == SYNTAX[:comment] || line.blank?
61
+ if line[0] == SYNTAX[:comment] || line.blank?
62
+ node[:attributes] += "\n" if node[:section] == :attributes
63
+ return node
64
+ end
62
65
  # looking at an attribute?
63
66
  if line =~ SYNTAX[:attribute]
64
67
  # exiting data section?
@@ -111,7 +114,9 @@ class Quandl::Format::Dataset::Load
111
114
 
112
115
  def parse_yaml_attributes(node)
113
116
  attrs = {}
114
- YAML.load( node[:attributes] ).symbolize_keys!.each do |key, value|
117
+ attributes = YAML.load( node[:attributes] )
118
+ raise 'Unparsable input' unless attributes.is_a? Hash
119
+ attributes.symbolize_keys!.each do |key, value|
115
120
  attrs[key.to_s.downcase.to_sym] = value
116
121
  end
117
122
  attrs
@@ -131,9 +136,21 @@ class Quandl::Format::Dataset::Load
131
136
 
132
137
  def log_yaml_parse_error(node, err)
133
138
  message = ""
134
- message += "Attribute parse error at line #{ node[:line] + err.line } column #{err.column}. #{err.problem} (#{err.class})\n" if node.has_key?(:line) && err.respond_to?(:line)
135
- message += "Did you forget to delimit the meta data section from the data section with a one or more dashes ('#{SYNTAX[:data]}')?\n" unless node[:attributes] =~ /^-/
136
- message += "Encountered error while parsing: \n " + node[:attributes].split("\n")[err.line - 1].to_s + "\n" if err.respond_to?(:line)
139
+ if err.message == 'Unparsable input'
140
+ message = "Input data is unparsable. Are you missing a colon (:) or a space after a colon?\n"
141
+ elsif err.is_a?(Psych::SyntaxError)
142
+ if err.problem =~ /mapping values are not allowed in this context/
143
+ message = "Syntax error before line #{1+node[:offset] + err.line}. Are you missing a colon (:) or a space after a colon?\n"
144
+ else
145
+ message += "Error parsing metadata. #{err.problem.capitalize} on line #{node[:offset] + err.line}\n"
146
+ if err.problem =~ /expected ':'/
147
+ message += "Did you forget to delimit the meta data section from the data section with a one or more dashes ('#{SYNTAX[:data]}')?\n"
148
+ end
149
+ end
150
+ else
151
+ message += "Attribute parse error at line #{ node[:line] + err.line } column #{err.column}. #{err.problem} (#{err.class})\n" if node.has_key?(:line) && err.respond_to?(:line)
152
+ message += "Encountered error while parsing: \n " + node[:attributes].split("\n")[err.line - 1].to_s + "\n" if err.respond_to?(:line)
153
+ end
137
154
  message += "--"
138
155
  Quandl::Logger.error(message)
139
156
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Format
3
- VERSION = "0.2.7"
3
+ VERSION = "0.2.8"
4
4
  end
5
5
  end
@@ -0,0 +1,2 @@
1
+ code foo
2
+ name: hello
@@ -0,0 +1,3 @@
1
+ code: FOO
2
+ name: Bar
3
+ description forgot the colon, damn.
@@ -2,6 +2,7 @@ code: "BLAKE_TEST_1"
2
2
  name: "A new title"
3
3
  description: "The description Date, Open, High"
4
4
  private: false
5
+ -
5
6
  Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
6
7
  2013-11-22,1252.0,454.95,448.2,450.0,450.0,1354405.0,6099.41
7
8
  2013-11-21,452.25,457.75,449.1,451.2,451.0,218881.0,992.94
@@ -9,13 +10,23 @@ Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
9
10
  code: "BLAKE_TEST_2"
10
11
  name: "A new title"
11
12
  description: "The description Date, Open, High"
13
+ -
12
14
  Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
13
15
  2013-11-22,1252.0,454.95,448.2,450.0,450.0,1354405.0,6099.41
14
16
  2013-11-21,452.25,457.75,449.1,451.2,451.0,218881.0,992.94
15
17
 
18
+ # Missing Dash in this one
16
19
  code: "BLAKE_TEST_3"
17
20
  name: "A new title"
18
21
  description: "The description Date, Open, High"
19
22
  Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
20
23
  2013-11-22,1252.0,454.95,448.2,450.0,450.0,1354405.0,6099.41
24
+ 2013-11-21,452.25,457.75,449.1,451.2,451.0,218881.0,992.94
25
+
26
+ code: "BLAKE_TEST_4"
27
+ name: "A new title"
28
+ description: "The description Date, Open, High"
29
+ -
30
+ Date,Open,High,Low,Last,Close,Total Trade Quantity,Turnover (Lacs)
31
+ 2013-11-22,1252.0,454.95,448.2,450.0,450.0,1354405.0,6099.41
21
32
  2013-11-21,452.25,457.75,449.1,451.2,451.0,218881.0,992.94
@@ -0,0 +1 @@
1
+ code:FOO
@@ -12,10 +12,11 @@ describe Quandl::Format::Dataset do
12
12
 
13
13
  it_should_expect_error 'invalid_data', /Date/
14
14
  it_should_expect_error 'unknown_attribute', /this_attribute_does_not_exist/
15
- it_should_expect_error 'mismatched_columns', /Expected 4 but found 5/
16
- it_should_expect_error 'mismatched_rows', /Expected 3 but found 4/
17
- it_should_expect_error 'invalid_yaml', /could not find expected ':'/
18
- it_should_expect_error 'missing_dashes', /Attribute parse error at line 28 column 1/
15
+ it_should_expect_error 'invalid_yaml', /Could not find expected ':'/
16
+ it_should_expect_error 'missing_dashes', /Could not find expected ':' on line 22/
19
17
  it_should_expect_error 'missing_dashes', /Did you forget to delimit the meta data section/
18
+ it_should_expect_error 'missing_colon', /Are you missing a colon/
19
+ it_should_expect_error 'missing_colon2', /Could not find expected ':' on line 3/
20
+ it_should_expect_error 'missing_space', /Are you missing a colon/
20
21
 
21
22
  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.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: quandl_client
@@ -157,7 +157,10 @@ files:
157
157
  - spec/fixtures/data/metadata_only.qdf
158
158
  - spec/fixtures/data/mismatched_columns.qdf
159
159
  - spec/fixtures/data/mismatched_rows.qdf
160
+ - spec/fixtures/data/missing_colon.qdf
161
+ - spec/fixtures/data/missing_colon2.qdf
160
162
  - spec/fixtures/data/missing_dashes.qdf
163
+ - spec/fixtures/data/missing_space.qdf
161
164
  - spec/fixtures/data/tabular.qdf
162
165
  - spec/fixtures/data/unknown_attribute.qdf
163
166
  - spec/fixtures/data/valid.qdf
@@ -204,7 +207,10 @@ test_files:
204
207
  - spec/fixtures/data/metadata_only.qdf
205
208
  - spec/fixtures/data/mismatched_columns.qdf
206
209
  - spec/fixtures/data/mismatched_rows.qdf
210
+ - spec/fixtures/data/missing_colon.qdf
211
+ - spec/fixtures/data/missing_colon2.qdf
207
212
  - spec/fixtures/data/missing_dashes.qdf
213
+ - spec/fixtures/data/missing_space.qdf
208
214
  - spec/fixtures/data/tabular.qdf
209
215
  - spec/fixtures/data/unknown_attribute.qdf
210
216
  - spec/fixtures/data/valid.qdf