bankofcanada_as_dataframe 0.1.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0abb0da0ebbf1a62900356917942cebea1e450109498aefc274a1c6b7c46fb1b
4
- data.tar.gz: 61bdb7b0ef3271c0c78ea93df3c5a3525a6abb537e1a61633fc210b5c626f591
3
+ metadata.gz: 601c936befc90414990a3c368cacd87bbfc9114aaf4b83bee57823b8f7a83caf
4
+ data.tar.gz: de615ad5c546432c0be657a74210d1f478801b25b80868b49ecc1c796c587a47
5
5
  SHA512:
6
- metadata.gz: bc7d6d816fd7372f6166fb7c36e0e02af23dde904d23cab801df7563205596a67f2415f948e9a258016f9d61256348ab23d771fd0a78fd02efbbf25943682973
7
- data.tar.gz: 032b3be1de9e5fda8201df378cd691ee23797048b4bfc625ee0919eb1616327f703d3c77694d92e9165aa1628acd516ee2cc59ee1711674c35165a7ad70edea8
6
+ metadata.gz: e0da623d5707c0eda1608d17a18c18816e0123382a2e46387d64378b4c807303d7b5672f47c576b844f669973df3cb9c48e3ae6d8597f86786ef764293fdecbb
7
+ data.tar.gz: 4e5187d6d99acb8ae58310f22d25996f4673f4cf55313d950eb6d1c4a15bc59508eaded5a96e6b2c822da2dd069a8dca8f2fabb83a632787f5695dd695592a08
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.14
data/.travis.yml CHANGED
@@ -2,5 +2,5 @@
2
2
  language: ruby
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.7.7
6
- before_install: gem install bundler -v 2.1.4
5
+ - 3.3.14
6
+ before_install: gem install bundler -v 4.0.19
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in bankofcanada_as_dataframe.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
7
- gem "none", "~> "
6
+ gem "rake", "~> 13.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "webmock", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bankofcanada_as_dataframe (0.2.1)
5
+ httparty (~> 0.25)
6
+ polars-df (= 0.27.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.10.0)
12
+ public_suffix (>= 2.0.2, < 8.0)
13
+ bigdecimal (4.1.3)
14
+ crack (1.0.1)
15
+ bigdecimal
16
+ rexml
17
+ csv (3.3.7)
18
+ diff-lcs (1.6.2)
19
+ hashdiff (1.3.0)
20
+ httparty (0.25.1)
21
+ csv
22
+ mini_mime (>= 1.0.0)
23
+ multi_xml (>= 0.5.2)
24
+ mini_mime (1.1.5)
25
+ multi_xml (0.9.1)
26
+ bigdecimal (>= 3.1, < 5)
27
+ polars-df (0.27.1-x86_64-linux)
28
+ public_suffix (7.0.5)
29
+ rake (13.4.2)
30
+ rexml (3.4.4)
31
+ rspec (3.13.2)
32
+ rspec-core (~> 3.13.0)
33
+ rspec-expectations (~> 3.13.0)
34
+ rspec-mocks (~> 3.13.0)
35
+ rspec-core (3.13.7)
36
+ rspec-support (~> 3.13.0)
37
+ rspec-expectations (3.13.6)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.13.0)
40
+ rspec-mocks (3.13.9)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.13.0)
43
+ rspec-support (3.13.8)
44
+ webmock (3.40.0)
45
+ addressable (>= 2.8.0)
46
+ crack (>= 0.3.2)
47
+ hashdiff (>= 0.4.0, < 2.0.0)
48
+
49
+ PLATFORMS
50
+ x86_64-linux
51
+
52
+ DEPENDENCIES
53
+ bankofcanada_as_dataframe!
54
+ rake (~> 13.0)
55
+ rspec (~> 3.0)
56
+ webmock (~> 3.0)
57
+
58
+ CHECKSUMS
59
+ addressable (2.10.0) sha256=5e13b9c001adf01dd65ad6e0d2a91d2bc07885c0ff2b83f48cbcd95e08d9de62
60
+ bankofcanada_as_dataframe (0.2.1)
61
+ bigdecimal (4.1.3) sha256=61ebe1e5e559bdc3cc6f2c0ee7f427321fc838f59611c294356eb04d6e21cf66
62
+ bundler (4.0.19) sha256=b48056e4c77fb3853cc47775b5447ede44aaa4f53c32f168014ab4fe86587d47
63
+ crack (1.0.1) sha256=ff4a10390cd31d66440b7524eb1841874db86201d5b70032028553130b6d4c7e
64
+ csv (3.3.7) sha256=15a3f16f6628da8664d455eb634e7f22031bcf53044923caf56975109e71b9f8
65
+ diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
66
+ hashdiff (1.3.0) sha256=0b6724b8f3fef3961acc09489b175698ce0b7fd22c9cc5aa559d280cc6b65649
67
+ httparty (0.25.1) sha256=354f84b766f9a3e077d64fc8b61a71c88e7c8a890eac4178d30d3269458c1dc5
68
+ mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef
69
+ multi_xml (0.9.1) sha256=7ce766b59c17241ed62976caeae1fae9b2431b263398c35396239a68c4a64e57
70
+ polars-df (0.27.1-x86_64-linux) sha256=3cb35fe50bfd783845976e6bc567a560d547dbded8a96887a2d5a658d01396e2
71
+ public_suffix (7.0.5) sha256=1a8bb08f1bbea19228d3bed6e5ed908d1cb4f7c2726d18bd9cadf60bc676f623
72
+ rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
73
+ rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142
74
+ rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
75
+ rspec-core (3.13.7) sha256=c64ff16d9788119805cbc6a3f4b6d87cc22417c2d25976a3330de136896b5469
76
+ rspec-expectations (3.13.6) sha256=bf538ca6d367ff5b0d85a87fdb5c0c6038f2cd1308a0eeba07476caa02d22f35
77
+ rspec-mocks (3.13.9) sha256=ea5c7ff3054a6098ca6039aacef80aec69d5a8a3ef80be8fc88337359b672a30
78
+ rspec-support (3.13.8) sha256=e4160030309b7e3e9d9863dfe720a35dfcc577162f5402cd68fc8c5258a0ffd6
79
+ webmock (3.40.0) sha256=6d88e99c220e911dc4451f1a3e7077c40c205df3583e162a10d5f1f29f5a9790
80
+
81
+ BUNDLED WITH
82
+ 4.0.19
data/README.md CHANGED
@@ -1,8 +1,16 @@
1
- # EconDataReader
1
+ # BankofcanadaAsDataframe
2
2
 
3
3
  Up to date remote economic data access for ruby, using Polars dataframes.
4
4
 
5
- This package will fetch economic and financial information from the Bank of Canada's API, and return the results as a Polars dataframe.
5
+ This package will fetch economic and financial information from the Bank of Canada's API, and return the results as a Polars dataframe. For details regarding the data available from the Bank of Canada, see https://www.bankofcanada.ca/valet/docs .
6
+
7
+
8
+ ## Requirements
9
+
10
+ - **Ruby**: >= 3.3
11
+ - **polars-df**: 0.27.1
12
+ - **httparty**: ~> 0.25
13
+
6
14
 
7
15
  ## Installation
8
16
 
@@ -23,13 +31,110 @@ Or install it yourself as:
23
31
 
24
32
  ## Usage
25
33
 
34
+ ### Fetching Series Data
35
+
36
+ Fetch data for a specific series by creating a client with the series code and calling `fetch`:
37
+
26
38
  ``` ruby
27
- BankofcanadaAsDataframe::Client.new('IEXE0102').fetch
39
+ 3.3.0 :001 > BankofcanadaAsDataframe::Client.new('IEXE0102').fetch
40
+ =>
41
+ shape: (2_504, 2)
42
+ ┌────────────┬────────┐
43
+ │ Timestamps ┆ Values │
44
+ │ --- ┆ --- │
45
+ │ date ┆ f64 │
46
+ ╞════════════╪════════╡
47
+ │ 2007-05-01 ┆ 1.1105 │
48
+ │ 2007-05-02 ┆ 1.1087 │
49
+ │ 2007-05-03 ┆ 1.1066 │
50
+ │ 2007-05-04 ┆ 1.1075 │
51
+ │ 2007-05-07 ┆ 1.1018 │
52
+ │ … ┆ … │
53
+ │ 2017-04-24 ┆ 1.3511 │
54
+ │ 2017-04-25 ┆ 1.3565 │
55
+ │ 2017-04-26 ┆ 1.3612 │
56
+ │ 2017-04-27 ┆ 1.3624 │
57
+ │ 2017-04-28 ┆ 1.365 │
58
+ └────────────┴────────┘
59
+ ```
60
+
61
+ You can filter by date range using the `start` and `fin` parameters:
62
+
63
+ ``` ruby
64
+ 3.3.0 :002 > BankofcanadaAsDataframe::Client.new('IEXE0102').fetch(start: '2010-01-01', fin: '2016-01-01')
65
+ =>
66
+ shape: (1_502, 2)
67
+ ┌────────────┬────────┐
68
+ │ Timestamps ┆ Values │
69
+ │ --- ┆ --- │
70
+ │ date ┆ f64 │
71
+ ╞════════════╪════════╡
72
+ │ 2010-01-04 ┆ 1.0414 │
73
+ │ 2010-01-05 ┆ 1.039 │
74
+ │ 2010-01-06 ┆ 1.0325 │
75
+ │ 2010-01-07 ┆ 1.035 │
76
+ │ 2010-01-08 ┆ 1.0309 │
77
+ │ … ┆ … │
78
+ │ 2015-12-23 ┆ 1.3857 │
79
+ │ 2015-12-24 ┆ 1.3845 │
80
+ │ 2015-12-29 ┆ 1.3823 │
81
+ │ 2015-12-30 ┆ 1.3885 │
82
+ │ 2015-12-31 ┆ 1.384 │
83
+ └────────────┴────────┘
84
+ ```
85
+
86
+ ### Listing Available Series
87
+
88
+ To discover available series codes and their descriptions, use the `list_series` class method:
89
+
90
+ ``` ruby
91
+ 3.3.0 :003 > BankofcanadaAsDataframe::Client.list_series
92
+ =>
93
+ shape: (1_234, 2)
94
+ ┌──────────────┬─────────────────────────────────────┐
95
+ │ Series ┆ Description │
96
+ │ --- ┆ --- │
97
+ │ str ┆ str │
98
+ ╞══════════════╪═════════════════════════════════════╡
99
+ │ IEXE0102 ┆ US dollar, noon spot rate; United… │
100
+ │ FXCADUSD ┆ Canadian dollar (noon); Canadian… │
101
+ │ … ┆ … │
102
+ └──────────────┴─────────────────────────────────────┘
28
103
  ```
29
104
 
30
105
  ## Documentation
31
106
 
32
- TBD
107
+ ### Public API
108
+
109
+ #### `Client.new(series_code, options = {})`
110
+
111
+ Creates a new client for fetching data for the specified series code.
112
+
113
+ **Parameters:**
114
+ - `series_code` (String): The Bank of Canada series code (e.g., 'IEXE0102')
115
+ - `options` (Hash): Optional configuration options
116
+
117
+ **Returns:** A new `BankofcanadaAsDataframe::Client` instance
118
+
119
+ #### `#fetch(start: nil, fin: nil)`
120
+
121
+ Fetches observations for the series and returns them as a Polars DataFrame.
122
+
123
+ **Parameters:**
124
+ - `start` (String or Date, optional): Filter observations on or after this date
125
+ - `fin` (String or Date, optional): Filter observations on or before this date
126
+
127
+ **Returns:** A `Polars::DataFrame` with columns:
128
+ - `Timestamps`: Date column containing observation dates
129
+ - `Values`: Float64 column containing observation values
130
+
131
+ #### `Client.list_series`
132
+
133
+ Class method that returns a list of all available series from the Bank of Canada.
134
+
135
+ **Returns:** A `Polars::DataFrame` with columns:
136
+ - `Series`: String column containing series codes
137
+ - `Description`: String column containing series label and description (separated by semicolon)
33
138
 
34
139
  ## Contributing
35
140
 
@@ -42,7 +147,21 @@ The following conventions are intended for this project.
42
147
  * When fetched, the dataset may be filtered based on optional (hash) arguments.
43
148
  * Output should be provided in a consistent DataFrame format (currently Polars::DataFrame).
44
149
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/bmck/econ_data_reader.
150
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bmck/bankofcanada_as_dataframe.
151
+
152
+
153
+ ## Testing
154
+
155
+ This gem uses RSpec for testing. All tests use webmock to stub HTTP requests, so no live network connections are made during testing.
156
+
157
+ To run the test suite:
158
+
159
+ $ bundle install
160
+ $ bundle exec rake spec
161
+
162
+ Or run tests directly with RSpec:
163
+
164
+ $ bundle exec rspec
46
165
 
47
166
 
48
167
  ## License
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
2
6
  task :default => :spec
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = "Economic and financial data from the Bank of Canada"
11
11
  spec.homepage = "https://github.com/bmck/bankofcanada_as_dataframe"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.3.0")
14
14
 
15
15
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
16
 
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  # Uncomment to register a new dependency of your gem
31
31
  # spec.add_dependency "typhoeus-gem", "~> 0.6.9"
32
- spec.add_dependency 'polars-df'
33
- spec.add_dependency 'httparty'
32
+ spec.add_dependency 'polars-df', '0.27.1'
33
+ spec.add_dependency 'httparty', '~> 0.25'
34
34
  end
@@ -0,0 +1,58 @@
1
+ require 'polars-df'
2
+ require 'httparty'
3
+ require 'date'
4
+
5
+ module BankofcanadaAsDataframe
6
+ class Client
7
+ # Get data for the given name from the Bank of Canada.
8
+
9
+ include ::HTTParty
10
+ base_uri "https://www.bankofcanada.ca/valet"
11
+ format :json
12
+
13
+ attr_reader :tag
14
+
15
+ def initialize(series, options={})
16
+ @tag = series
17
+ end
18
+
19
+ def fetch(start: nil, fin: nil)
20
+ dta = observations({}).parsed_response['observations']
21
+ dta = dta.select{|d| start.nil? ? true : Date.parse(d['d']) >= _parse_date(start) } unless start.nil?
22
+ dta = dta.select{|d| fin.nil? ? true : Date.parse(d['d']) <= _parse_date(fin) } unless fin.nil?
23
+
24
+ dates = dta.map{|d| Date.parse(d['d']) }
25
+ vals = dta.map{|d| d[tag]['v'].to_f }
26
+
27
+ Polars::DataFrame.new({Timestamps: dates, Values: vals})
28
+ end
29
+
30
+ def self.list_series
31
+ dta = (get('/lists/series/json').parsed_response)['series']
32
+
33
+ series = dta.keys
34
+ desc = series.map{|s| [dta[s]['label'], dta[s]['description']].join('; ') }
35
+
36
+ Polars::Config.set_tbl_rows(-1)
37
+ Polars::DataFrame.new({Series: series, Description: desc})
38
+ end
39
+
40
+ protected
41
+
42
+ def default_options
43
+ { }
44
+ end
45
+
46
+ private
47
+
48
+ def observations(options={})
49
+ self.class.get("/observations/#{tag}/json", :query => options.merge(self.default_options))
50
+ end
51
+
52
+ def _parse_date(date_input)
53
+ return date_input if date_input.is_a?(Date)
54
+ Date.parse(date_input.to_s)
55
+ end
56
+
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module BankofcanadaAsDataframe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankofcanada_as_dataframe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill McKinnon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: polars-df
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.27.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.27.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.25'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.25'
41
41
  description: Economic and financial data from the Bank of Canada
42
42
  email:
43
43
  - bill.mckinnon@bmck.org
@@ -46,8 +46,10 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".ruby-version"
49
50
  - ".travis.yml"
50
51
  - Gemfile
52
+ - Gemfile.lock
51
53
  - LICENSE.txt
52
54
  - README.md
53
55
  - Rakefile
@@ -55,6 +57,7 @@ files:
55
57
  - bin/console
56
58
  - bin/setup
57
59
  - lib/bankofcanada_as_dataframe.rb
60
+ - lib/bankofcanada_as_dataframe/client.rb
58
61
  - lib/bankofcanada_as_dataframe/version.rb
59
62
  homepage: https://github.com/bmck/bankofcanada_as_dataframe
60
63
  licenses:
@@ -71,14 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
74
  requirements:
72
75
  - - ">="
73
76
  - !ruby/object:Gem::Version
74
- version: 2.3.0
77
+ version: 3.3.0
75
78
  required_rubygems_version: !ruby/object:Gem::Requirement
76
79
  requirements:
77
80
  - - ">="
78
81
  - !ruby/object:Gem::Version
79
82
  version: '0'
80
83
  requirements: []
81
- rubygems_version: 3.1.6
84
+ rubygems_version: 3.5.22
82
85
  signing_key:
83
86
  specification_version: 4
84
87
  summary: Economic and financial data from the Bank of Canada