quandl_data 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/quandl/data/table/operations.rb +17 -12
- data/lib/quandl/data/version.rb +1 -1
- data/spec/quandl/data_spec.rb +52 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a671dc7961dc824080203af92205cbf45401c38c
|
4
|
+
data.tar.gz: 573b0ccfabfe0b929749f6b2d1d1ff40f10d22fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e7dd6185d4c8947fffe2b450fd7c7d6ce217576c1a47e51a7f7cffa2b3c0712a75499f5f7fed0057bec51d71add108c841b3b801e4e756f2932e9ed86a42112
|
7
|
+
data.tar.gz: 2166730089b5375f8eba61a11db1108539bc3e9bf7f3f0c5299e6b8ee6f767675c2eabec9475f564e2a783bc12178e436d9477825dcf9390d20539f1ffd3152f
|
@@ -45,15 +45,15 @@ module Operations
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def to_date!
|
48
|
-
@data_array = to_date.
|
48
|
+
@data_array = to_date.data_array
|
49
49
|
self
|
50
50
|
end
|
51
51
|
def to_date
|
52
|
-
Parse.julian_to_date data_array
|
52
|
+
Table.new( Parse.julian_to_date( data_array ) )
|
53
53
|
end
|
54
54
|
|
55
55
|
def trim_start!(trim_date)
|
56
|
-
@data_array = trim_start(trim_date).
|
56
|
+
@data_array = trim_start(trim_date).data_array
|
57
57
|
self
|
58
58
|
end
|
59
59
|
def trim_start(trim_date)
|
@@ -63,14 +63,15 @@ module Operations
|
|
63
63
|
# find index
|
64
64
|
return self unless trim_date.is_a?(Integer)
|
65
65
|
# reject rows with dates less than
|
66
|
-
sort_descending.delete_if do |row|
|
66
|
+
data = sort_descending.delete_if do |row|
|
67
67
|
row_date = row[0]
|
68
68
|
row_date < trim_date
|
69
69
|
end
|
70
|
+
Table.new(data)
|
70
71
|
end
|
71
72
|
|
72
73
|
def trim_end!(trim_date)
|
73
|
-
@data_array = trim_end(trim_date).
|
74
|
+
@data_array = trim_end(trim_date).data_array
|
74
75
|
self
|
75
76
|
end
|
76
77
|
def trim_end(trim_date)
|
@@ -80,35 +81,39 @@ module Operations
|
|
80
81
|
# find index
|
81
82
|
return self unless trim_date.is_a?(Integer)
|
82
83
|
# reject rows with dates less than
|
83
|
-
sort_descending.delete_if do |row|
|
84
|
+
data = sort_descending.delete_if do |row|
|
84
85
|
row_date = row[0]
|
85
86
|
row_date > trim_date
|
86
87
|
end
|
88
|
+
Table.new(data)
|
87
89
|
end
|
88
90
|
|
89
|
-
def limit(amount)
|
90
|
-
@data_array =
|
91
|
+
def limit!(amount)
|
92
|
+
@data_array = limit(amount).data_array
|
91
93
|
self
|
92
94
|
end
|
95
|
+
def limit(amount)
|
96
|
+
Table.new( data_array[0..( amount.to_i - 1 )] )
|
97
|
+
end
|
93
98
|
|
94
99
|
def sort_order(dir)
|
95
100
|
dir == :asc ? sort_ascending! : sort_descending!
|
96
101
|
end
|
97
102
|
|
98
103
|
def sort_ascending!
|
99
|
-
@data_array = sort_ascending.
|
104
|
+
@data_array = sort_ascending.data_array
|
100
105
|
self
|
101
106
|
end
|
102
107
|
def sort_ascending
|
103
|
-
Table.new( Parse.sort( data_array, :asc ), frequency: frequency )
|
108
|
+
Table.new( Parse.sort( data_array.dup, :asc ), frequency: frequency )
|
104
109
|
end
|
105
110
|
|
106
111
|
def sort_descending!
|
107
|
-
@data_array = sort_descending.
|
112
|
+
@data_array = sort_descending.data_array
|
108
113
|
self
|
109
114
|
end
|
110
115
|
def sort_descending
|
111
|
-
Table.new( Parse.sort( data_array, :desc ), frequency: frequency )
|
116
|
+
Table.new( Parse.sort( data_array.dup, :desc ), frequency: frequency )
|
112
117
|
end
|
113
118
|
|
114
119
|
def transform(*args)
|
data/lib/quandl/data/version.rb
CHANGED
data/spec/quandl/data_spec.rb
CHANGED
@@ -47,22 +47,62 @@ describe Quandl::Data::Table do
|
|
47
47
|
subject.limit(2).count.should eq 2
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
describe "to_date" do
|
51
|
+
|
52
|
+
it "should convert julian dates to dates" do
|
53
|
+
subject.to_date.first.first.should be_a Date
|
54
|
+
end
|
55
|
+
|
52
56
|
end
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
describe "trim_end" do
|
59
|
+
|
60
|
+
it "should delete everything after trim_end" do
|
61
|
+
data = Quandl::Data::Random.table( nils: false, rows: 10, columns: 1 ).sort_descending
|
62
|
+
date = data[1][0]
|
63
|
+
data.trim_end!(date)
|
64
|
+
data.data_array.should be_a Array
|
65
|
+
data.count.should eq 9
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be chainable" do
|
69
|
+
subject.trim_end(subject.first.first).trim_end(subject.last.first)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not alter the original object" do
|
73
|
+
data = subject.trim_end(subject[2][0])
|
74
|
+
subject.count.should eq 4
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should alter the original object" do
|
78
|
+
subject.trim_end!(subject[2][0])
|
79
|
+
subject.count.should eq 2
|
80
|
+
end
|
81
|
+
|
58
82
|
end
|
59
83
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
84
|
+
describe "trim_start" do
|
85
|
+
|
86
|
+
it "should delete everything before trim_start" do
|
87
|
+
data = Quandl::Data::Random.table( nils: false, rows: 10, columns: 1 ).sort_descending
|
88
|
+
date = data[-2][0]
|
89
|
+
data.trim_start(date).count.should eq 9
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be chainable" do
|
93
|
+
subject.trim_start(subject.first.first).trim_end(subject.last.first)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should not alter the original object" do
|
97
|
+
data = subject.trim_start(subject[2][0])
|
98
|
+
subject.count.should eq 4
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should alter the original object" do
|
102
|
+
subject.trim_start!(subject[-3][0])
|
103
|
+
subject.count.should eq 2
|
104
|
+
end
|
105
|
+
|
66
106
|
end
|
67
107
|
|
68
108
|
end
|