quandl_operation 0.2.0 → 0.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bc77362c57fff96b7d468ed11ecf3ced455cbcc
|
4
|
+
data.tar.gz: d63f23908949e9bd62b909772167c0569d146e66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d865104a72d0e0f9b01805489adbdd9ba1c96415e668191ce403c85e3766d497abd5276ade91eb504433f5e3f28e6757aa89f78010d6d397e3602ab5ebfea858
|
7
|
+
data.tar.gz: 5679b97f828bad24bdf8b53db30d01f6be47cb88f5429aba204d752c1d47e5b7d47f97e7b875d9128fe53da1ef217c1b4e7ac01afae7618a8879bec2171541d2
|
data/UPGRADE.md
CHANGED
@@ -8,22 +8,29 @@ class Collapse
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
-
def perform(data,
|
12
|
-
|
13
|
-
#
|
14
|
-
|
11
|
+
def perform(data, type)
|
12
|
+
assert_valid_arguments!(data, type)
|
13
|
+
# nothing to do with an empty array
|
14
|
+
return data unless data.compact.present?
|
15
15
|
# ensure data is in expected format
|
16
16
|
data = Parse.to_jd(data)
|
17
|
+
# source order
|
18
|
+
order = Parse.sort_order?(data)
|
17
19
|
# operations expect data in ascending order
|
18
20
|
data = Parse.sort( data, :asc )
|
19
21
|
# collapse
|
20
|
-
data = collapse(data,
|
22
|
+
data = collapse(data, type)
|
21
23
|
# return to original order
|
22
24
|
data = Parse.sort( data, :desc ) if order == :desc
|
23
25
|
# onwards
|
24
26
|
data
|
25
27
|
end
|
26
28
|
|
29
|
+
def assert_valid_arguments!(data, type)
|
30
|
+
raise ArgumentError, "data must be an Array. Received: #{data.class}" unless data.is_a?(Array)
|
31
|
+
raise ArgumentError, "frequency must be one of #{valid_collapses}. Received: #{type}" unless valid?(type)
|
32
|
+
end
|
33
|
+
|
27
34
|
def valid_collapse?(type)
|
28
35
|
valid?(type)
|
29
36
|
end
|
@@ -133,7 +133,9 @@ class Parse
|
|
133
133
|
# otherwise cast string jds to int
|
134
134
|
output = []
|
135
135
|
data.each_with_index do |row, index|
|
136
|
-
|
136
|
+
row = parse_date_string(row) rescue raise_date_format_error!( row, index, :date_strings_to_jd )
|
137
|
+
row[0] = row[0].jd
|
138
|
+
output << row
|
137
139
|
end
|
138
140
|
output
|
139
141
|
end
|
@@ -6,7 +6,9 @@ class Transform
|
|
6
6
|
class << self
|
7
7
|
|
8
8
|
def perform( data, type )
|
9
|
-
|
9
|
+
assert_valid_arguments!(data, type)
|
10
|
+
# nothing to do with an empty array
|
11
|
+
return data unless data.compact.present?
|
10
12
|
# original order
|
11
13
|
order = Parse.sort_order?(data)
|
12
14
|
# operations expect data in ascending order
|
@@ -21,6 +23,11 @@ class Transform
|
|
21
23
|
data
|
22
24
|
end
|
23
25
|
|
26
|
+
def assert_valid_arguments!(data, type)
|
27
|
+
raise ArgumentError, "data must be an Array. Received: #{data.class}" unless data.is_a?(Array)
|
28
|
+
raise ArgumentError, "frequency must be one of #{valid_transformations}. Received: #{type}" unless valid?(type)
|
29
|
+
end
|
30
|
+
|
24
31
|
def valid_transformation?(type)
|
25
32
|
valid?(type)
|
26
33
|
end
|
@@ -46,10 +46,10 @@ describe Quandl::Operation::Collapse do
|
|
46
46
|
describe ".perform" do
|
47
47
|
|
48
48
|
let(:data){
|
49
|
-
[[2456537, 56.2, nil, nil],
|
49
|
+
Quandl::Operation::Parse.to_date([[2456537, 56.2, nil, nil],
|
50
50
|
[2456518, 55.7, nil, nil], [2456506, nil, 136133.0, nil],
|
51
51
|
[2456487, 55.4, nil, nil], [2456475, nil, 135964.0, nil],
|
52
|
-
[2456457, 50.9, nil, nil], [2456445, nil, 135860.0, nil]]
|
52
|
+
[2456457, 50.9, nil, nil], [2456445, nil, 135860.0, nil]])
|
53
53
|
}
|
54
54
|
|
55
55
|
it "should collapse data with nils" do
|