fred_as_dataframe 0.1.1 → 0.2.0
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/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +41 -0
- data/Gemfile +2 -3
- data/README.md +64 -12
- data/Rakefile +4 -0
- data/fred_as_dataframe.gemspec +8 -2
- data/lib/fred_as_dataframe/client.rb +13 -4
- data/lib/fred_as_dataframe/version.rb +1 -1
- metadata +80 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71c5e1e6483f35362a41afcabab7bc5fab1b5f90ceb5e9a8df9b497ca7c31bb3
|
|
4
|
+
data.tar.gz: 8edf3ed442f2110b73d0ce275ad846eb28a0cecafb883f4c4ed78db103b30bdf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d3b99ccecf9c7255a4457d786c576f42352f45bd56343eddd3affb11e9d0955c10db41d3a0abfcb542592f5ee0fe0edd362852df2035cca07753b19509fd772
|
|
7
|
+
data.tar.gz: 96ff1798bb8e1549600a9877152e1aa1ea1b5f0cde288dc2047602f17b9b155cc9aee1ec34c0932ad36505409a42f4f33ce6158ee395005611613fc387b7ec8f
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.3.0
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-08-28
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- **BREAKING**: Raised minimum required Ruby version from >= 2.3.0 to >= 3.3
|
|
12
|
+
- Pinned Ruby version to 3.3.0 in Gemfile and .ruby-version
|
|
13
|
+
- Pinned polars-df dependency to exactly 0.27.1 (requires Ruby >= 3.3)
|
|
14
|
+
- Updated README Ruby version examples from 3.1.2 to 3.3.0
|
|
15
|
+
|
|
16
|
+
## [0.1.2] - 2026-08-28
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- Comprehensive test suite using RSpec, VCR, and WebMock
|
|
20
|
+
- Tests for Client class including initialization, configuration, and fetch operations
|
|
21
|
+
- Tests for date filtering (start and fin parameters)
|
|
22
|
+
- Tests for API key configuration from class variable and options
|
|
23
|
+
- Testing documentation in README
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- Fixed undefined variable `nm` in error message (now correctly uses `@tag`)
|
|
27
|
+
- Fixed README title from "EconDataReader" to "FredAsDataframe"
|
|
28
|
+
- Fixed configuration documentation to use `config.api_key` instead of `config.fred_api_key`
|
|
29
|
+
- Fixed Rakefile to properly define `:spec` task so `rake` command works
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- Updated gemspec to include test dependencies (rspec, vcr, webmock, rake)
|
|
33
|
+
- Improved README configuration section with clearer examples
|
|
34
|
+
|
|
35
|
+
## [0.1.1] - Previous Release
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
- Initial release with FRED data fetching functionality
|
|
39
|
+
- Support for Polars DataFrame output
|
|
40
|
+
- Date range filtering with start and fin parameters
|
|
41
|
+
- Hardcoded SP500 data for monthly frequency
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# FredAsDataframe
|
|
2
2
|
|
|
3
3
|
Up to date remote economic data access for ruby, using Polars dataframes.
|
|
4
4
|
|
|
5
5
|
This package will fetch economic and financial information from the Federal Reserve Economic Database, and return the results as a Polars Dataframe. You will need an API key that can be fetched from the FRED website at https://fredaccount.stlouisfed.org/apikeys .
|
|
6
6
|
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Ruby >= 3.3
|
|
10
|
+
- polars-df ~> 0.27.1
|
|
11
|
+
|
|
7
12
|
## Installation
|
|
8
13
|
|
|
9
14
|
Add this line to your application's Gemfile:
|
|
@@ -27,10 +32,22 @@ Some data sources will require the specification of an API key. These keys shou
|
|
|
27
32
|
|
|
28
33
|
```ruby
|
|
29
34
|
FredAsDataframe::Client.configure do |config|
|
|
30
|
-
config.
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
config.api_key = '1234567890ABCDEF'
|
|
36
|
+
end
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Alternatively, you can read the API key from a file:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
FredAsDataframe::Client.configure do |config|
|
|
43
|
+
config.api_key = File.read(File.join('', 'home', 'user', '.fred_api_key.txt')).strip
|
|
33
44
|
end
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
You can also pass the API key directly when creating a client instance:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
client = FredAsDataframe::Client.new('UNRATE', api_key: '1234567890ABCDEF')
|
|
34
51
|
```
|
|
35
52
|
|
|
36
53
|
## Usage
|
|
@@ -38,13 +55,13 @@ end
|
|
|
38
55
|
Consider the following transcript.
|
|
39
56
|
|
|
40
57
|
``` ruby
|
|
41
|
-
3.
|
|
58
|
+
3.3.0 :001 > a = FredAsDataframe::Client.new('UNRATE')
|
|
42
59
|
=> #<FredAsDataframe::Client:0x0000000105f1dbb8 @api_key="1234567890ABCDEF", @tag="UNRATE">
|
|
43
|
-
3.
|
|
60
|
+
3.3.0 :002 > b = a.fetch
|
|
44
61
|
=>
|
|
45
62
|
shape: (919, 2)
|
|
46
63
|
...
|
|
47
|
-
3.
|
|
64
|
+
3.3.0 :003 > b
|
|
48
65
|
=>
|
|
49
66
|
shape: (919, 2)
|
|
50
67
|
┌────────────┬────────┐
|
|
@@ -64,13 +81,13 @@ shape: (919, 2)
|
|
|
64
81
|
│ 2024-06-01 ┆ 4.1 │
|
|
65
82
|
│ 2024-07-01 ┆ 4.3 │
|
|
66
83
|
└────────────┴────────┘
|
|
67
|
-
3.
|
|
84
|
+
3.3.0 :004 > a = FredAsDataframe::Client.new('AAA')
|
|
68
85
|
=> #<FredAsDataframe::Client:0x0000000106077d38 @api_key="1234567890ABCDEF", @tag="AAA">
|
|
69
|
-
3.
|
|
86
|
+
3.3.0 :005 > b = a.fetch
|
|
70
87
|
=>
|
|
71
88
|
shape: (1_267, 2)
|
|
72
89
|
...
|
|
73
|
-
3.
|
|
90
|
+
3.3.0 :006 > b
|
|
74
91
|
=>
|
|
75
92
|
shape: (1_267, 2)
|
|
76
93
|
┌────────────┬──────┐
|
|
@@ -93,9 +110,44 @@ shape: (1_267, 2)
|
|
|
93
110
|
|
|
94
111
|
```
|
|
95
112
|
|
|
96
|
-
##
|
|
113
|
+
## Testing
|
|
114
|
+
|
|
115
|
+
This gem uses RSpec for testing. To run the test suite:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
bundle install
|
|
119
|
+
bundle exec rake
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Or run RSpec directly:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
bundle exec rspec
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The test suite uses VCR and WebMock to record and replay HTTP interactions with the FRED API, ensuring tests run quickly and don't require a live API connection or API key.
|
|
129
|
+
|
|
130
|
+
### Running Tests with Coverage
|
|
131
|
+
|
|
132
|
+
Tests are configured with fixtures that mock FRED API responses, so you don't need a FRED API key to run the test suite.
|
|
133
|
+
|
|
134
|
+
## API Documentation
|
|
135
|
+
|
|
136
|
+
### Client#new(series_id, options = {})
|
|
137
|
+
|
|
138
|
+
Creates a new FRED data client for the specified series.
|
|
139
|
+
|
|
140
|
+
- `series_id` - FRED series identifier (e.g., 'UNRATE', 'AAA', 'SP500')
|
|
141
|
+
- `options` - Optional hash with `:api_key` to override configured API key
|
|
142
|
+
|
|
143
|
+
### Client#fetch(start: nil, fin: nil)
|
|
144
|
+
|
|
145
|
+
Fetches data from FRED and returns a Polars DataFrame.
|
|
146
|
+
|
|
147
|
+
- `start` - Optional start date (String or Date) to filter data from this date forward
|
|
148
|
+
- `fin` - Optional end date (String or Date) to filter data up to this date
|
|
97
149
|
|
|
98
|
-
|
|
150
|
+
Returns a Polars DataFrame with timestamp and value columns.
|
|
99
151
|
|
|
100
152
|
## Contributing
|
|
101
153
|
|
data/Rakefile
CHANGED
data/fred_as_dataframe.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.description = "Integrated economic and financial data from FRED"
|
|
11
11
|
spec.homepage = "https://github.com/bmck/fred_as_dataframe"
|
|
12
12
|
spec.license = "MIT"
|
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.3")
|
|
14
14
|
|
|
15
15
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
16
16
|
|
|
@@ -29,6 +29,12 @@ 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'
|
|
32
|
+
spec.add_dependency 'polars-df', '0.27.1'
|
|
33
33
|
spec.add_dependency 'httparty'
|
|
34
|
+
|
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
|
36
|
+
spec.add_development_dependency 'vcr', '~> 6.1'
|
|
37
|
+
spec.add_development_dependency 'webmock', '~> 3.18'
|
|
38
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
39
|
+
spec.add_development_dependency 'rack', '~> 3.0'
|
|
34
40
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'polars-df'
|
|
2
2
|
require 'httparty'
|
|
3
3
|
require 'csv'
|
|
4
|
+
require 'date'
|
|
4
5
|
|
|
5
6
|
module FredAsDataframe
|
|
6
7
|
class Client
|
|
@@ -26,11 +27,12 @@ module FredAsDataframe
|
|
|
26
27
|
i = interval[0..-2].to_i
|
|
27
28
|
|
|
28
29
|
begin
|
|
29
|
-
data = data.select{ |date, _| (start.nil? || date >= start.
|
|
30
|
+
data = data.select{ |date, _| (start.nil? || date >= Date.parse(start.to_s)) } unless start.nil?
|
|
31
|
+
data = data.select{ |date, _| (fin.nil? || date <= Date.parse(fin.to_s)) } unless fin.nil?
|
|
30
32
|
data = data.each_slice(i).map(&:first)
|
|
31
33
|
rescue KeyError => e
|
|
32
34
|
if data.keys[3].to_s[7, 5] == "Error"
|
|
33
|
-
raise IOError, "Failed to get the data. Check that '#{
|
|
35
|
+
raise IOError, "Failed to get the data. Check that '#{@tag}' is a valid FRED series."
|
|
34
36
|
else
|
|
35
37
|
raise e
|
|
36
38
|
end
|
|
@@ -55,8 +57,15 @@ module FredAsDataframe
|
|
|
55
57
|
if nm == 'SP500' && i == 'm'
|
|
56
58
|
resp = sp500
|
|
57
59
|
else
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
http_resp = self.class.get(_url(nm, interval[-1]))
|
|
61
|
+
parsed = http_resp.parsed_response
|
|
62
|
+
|
|
63
|
+
# Handle API errors
|
|
64
|
+
if parsed.is_a?(Hash) && parsed['error_message']
|
|
65
|
+
raise IOError, "Failed to get the data. Check that '#{nm}' is a valid FRED series. Error: #{parsed['error_message']}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
resp = parsed['observations']['observation']
|
|
60
69
|
resp = "date, #{nm}\n" + resp.map{|r| "#{r['date']},#{r['value']}" }.join("\n")
|
|
61
70
|
end
|
|
62
71
|
data = CSV.parse(resp, headers: true, header_converters: :symbol, converters: [:date, :float])
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fred_as_dataframe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bill McKinnon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-08-28 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:
|
|
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:
|
|
26
|
+
version: 0.27.1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: httparty
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -38,6 +38,76 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.12'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.12'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: vcr
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '6.1'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '6.1'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: webmock
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.18'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.18'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '13.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '13.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rack
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '3.0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '3.0'
|
|
41
111
|
description: Integrated economic and financial data from FRED
|
|
42
112
|
email:
|
|
43
113
|
- bill.mckinnon@bmck.org
|
|
@@ -46,7 +116,9 @@ extensions: []
|
|
|
46
116
|
extra_rdoc_files: []
|
|
47
117
|
files:
|
|
48
118
|
- ".gitignore"
|
|
119
|
+
- ".ruby-version"
|
|
49
120
|
- ".travis.yml"
|
|
121
|
+
- CHANGELOG.md
|
|
50
122
|
- Gemfile
|
|
51
123
|
- LICENSE.txt
|
|
52
124
|
- README.md
|
|
@@ -72,14 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
72
144
|
requirements:
|
|
73
145
|
- - ">="
|
|
74
146
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
147
|
+
version: '3.3'
|
|
76
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
149
|
requirements:
|
|
78
150
|
- - ">="
|
|
79
151
|
- !ruby/object:Gem::Version
|
|
80
152
|
version: '0'
|
|
81
153
|
requirements: []
|
|
82
|
-
rubygems_version: 3.
|
|
154
|
+
rubygems_version: 3.5.22
|
|
83
155
|
signing_key:
|
|
84
156
|
specification_version: 4
|
|
85
157
|
summary: Integrated economic and financial data from FRED
|