redfin_as_dataframe 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff5109eae1acf4c4b239aba97337e3400865ea5abf175e7434cce92ce06c8d07
4
- data.tar.gz: dd003b5db37739d3b5c5db2eb9674da57a79a92974b142774bd567e27c08bc65
3
+ metadata.gz: de325bc8ad975242070ac2c49f4f5c9ba95ba58e9b2bf05f8a243aee3e073363
4
+ data.tar.gz: a4a3879f60b2fc0379ebb367d6709c47ba50b3e3b12ea7fec23f2632a9c5d62c
5
5
  SHA512:
6
- metadata.gz: fd8516a3ea881655a30c1be76b4718184a60fd46340678eba22af0261053fe5c1e56ae219b883412337012621428aca11f5d0087e282d7d197746011eb6d1092
7
- data.tar.gz: 5ae220fcecf9d9e5d31675f8103fb8422c0f70bfcc5d969acb05e5ddc2cc2264096bccf41e9d12964a873b1ff591ffea462e9651e405a2948ca3915e2bded9e7
6
+ metadata.gz: ee8235b783a269d7f844a11dfe5e130dc75e964b05c26f3b85a7382cc09fd4beb2f7766735ad39b36030779e2b42fc1e2aab71ee2ad91e4cb8eb6a29e4253890
7
+ data.tar.gz: 0fbeeef954715f259e631437e23d6f3a9af16a24a944725521e49ee4acb4aefcfbf10ffaa7e27e0991635a80c9ca41c19fcd468e48a489fce5d8d2704a969679
data/.gitignore CHANGED
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /vendor/bundle/
10
+ *.gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.6
data/Gemfile CHANGED
@@ -1,7 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ ruby '3.3.6'
4
+
3
5
  # Specify your gem's dependencies in redfin_as_dataframe.gemspec
4
6
  gemspec
5
7
 
6
8
  gem "rake", "~> 12.0"
7
- gem "none", "~> "
9
+ gem "rspec", "~> 3.0"
10
+ gem "webmock", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ redfin_as_dataframe (0.2.0)
5
+ httparty
6
+ polars-df (= 0.27.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.9.0)
12
+ public_suffix (>= 2.0.2, < 8.0)
13
+ bigdecimal (4.1.2)
14
+ crack (1.0.1)
15
+ bigdecimal
16
+ rexml
17
+ csv (3.3.6)
18
+ diff-lcs (1.6.2)
19
+ hashdiff (1.2.1)
20
+ httparty (0.24.2)
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-aarch64-linux)
28
+ polars-df (0.27.1-aarch64-linux-musl)
29
+ polars-df (0.27.1-arm64-darwin)
30
+ polars-df (0.27.1-x86_64-darwin)
31
+ polars-df (0.27.1-x86_64-linux)
32
+ polars-df (0.27.1-x86_64-linux-musl)
33
+ public_suffix (7.0.5)
34
+ rake (12.3.3)
35
+ rexml (3.4.4)
36
+ rspec (3.13.2)
37
+ rspec-core (~> 3.13.0)
38
+ rspec-expectations (~> 3.13.0)
39
+ rspec-mocks (~> 3.13.0)
40
+ rspec-core (3.13.6)
41
+ rspec-support (~> 3.13.0)
42
+ rspec-expectations (3.13.5)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.13.0)
45
+ rspec-mocks (3.13.8)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.13.0)
48
+ rspec-support (3.13.7)
49
+ webmock (3.26.3)
50
+ addressable (>= 2.8.0)
51
+ crack (>= 0.3.2)
52
+ hashdiff (>= 0.4.0, < 2.0.0)
53
+
54
+ PLATFORMS
55
+ aarch64-linux
56
+ aarch64-linux-musl
57
+ arm64-darwin
58
+ x86_64-darwin
59
+ x86_64-linux
60
+ x86_64-linux-musl
61
+
62
+ DEPENDENCIES
63
+ rake (~> 12.0)
64
+ redfin_as_dataframe!
65
+ rspec (~> 3.0)
66
+ webmock (~> 3.0)
67
+
68
+ RUBY VERSION
69
+ ruby 3.3.6p108
70
+
71
+ BUNDLED WITH
72
+ 2.5.22
data/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # RedfinAsDataframe
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/redfin_as_dataframe`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Up to date housing market data access for Ruby, using Polars dataframes.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This gem fetches housing market information from Redfin's public data API and returns the results as a Polars dataframe. For details regarding the data available from Redfin, see https://www.redfin.com/news/data-center/ .
6
+
7
+ ## Requirements
8
+
9
+ - Ruby >= 3.3
10
+ - polars-df 0.27.1
6
11
 
7
12
  ## Installation
8
13
 
@@ -22,17 +27,82 @@ Or install it yourself as:
22
27
 
23
28
  ## Usage
24
29
 
25
- TODO: Write usage instructions here
30
+ ### Basic Usage
26
31
 
27
- ## Development
32
+ Fetch all available national housing market data:
33
+
34
+ ```ruby
35
+ require 'redfin_as_dataframe'
36
+
37
+ national = RedfinAsDataframe::National.new
38
+ df = national.fetch
39
+ ```
40
+
41
+ This returns a Polars DataFrame with housing market metrics including median sale prices, inventory, months of supply, and more.
42
+
43
+ ### Filtering by Date Range
44
+
45
+ You can filter data by specifying start and/or end dates:
46
+
47
+ ```ruby
48
+ # Fetch data from a specific start date
49
+ national = RedfinAsDataframe::National.new
50
+ df = national.fetch(start: '2020-01-01')
51
+
52
+ # Fetch data up to a specific end date
53
+ df = national.fetch(fin: '2023-12-31')
54
+
55
+ # Fetch data within a date range
56
+ df = national.fetch(start: '2020-01-01', fin: '2023-12-31')
57
+ ```
58
+
59
+ The `start` parameter filters to include only data where `period_begin` is on or after the specified date.
60
+ The `fin` parameter filters to include only data where `period_end` is on or before the specified date.
28
61
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake none` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+ ### Selecting Specific Data Series
63
+
64
+ You can fetch a specific data series by passing the column name to the initializer:
65
+
66
+ ```ruby
67
+ # Fetch only median sale price data
68
+ national = RedfinAsDataframe::National.new('median_sale_price')
69
+ df = national.fetch
70
+
71
+ # The returned DataFrame will contain only 'Timestamps' and 'median_sale_price' columns
72
+ ```
73
+
74
+ Available series include:
75
+ - `median_sale_price`, `median_list_price`
76
+ - `median_ppsf` (price per square foot), `median_list_ppsf`
77
+ - `homes_sold`, `pending_sales`, `new_listings`, `inventory`
78
+ - `months_of_supply`, `median_dom` (days on market)
79
+ - `avg_sale_to_list`, `sold_above_list`, `price_drops`
80
+ - And many more (see the full TSV data for all available columns)
81
+
82
+ ## Testing
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ The test suite uses RSpec and includes:
87
+ - Unit tests for the `National` class
88
+ - Mocked HTTP requests (no live API calls during testing)
89
+ - Tests for date filtering and data series selection
90
+
91
+ To run the tests:
92
+
93
+ $ bundle exec rake spec
94
+
95
+ Or run tests directly with RSpec:
96
+
97
+ $ bundle exec rspec
98
+
99
+ ## Development
30
100
 
31
101
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
102
 
33
103
  ## Contributing
34
104
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/redfin_as_dataframe.
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bmck/redfin_as_dataframe.
36
106
 
37
107
 
38
108
  ## 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
@@ -0,0 +1,50 @@
1
+ require 'polars-df'
2
+ require 'httparty'
3
+ require 'zlib'
4
+ require 'stringio'
5
+ require 'csv'
6
+ require 'date'
7
+
8
+ module RedfinAsDataframe
9
+ class National
10
+ # Get data for Redfin national housing market metrics.
11
+
12
+ include ::HTTParty
13
+
14
+ attr_reader :tag, :ary
15
+
16
+ def initialize(series = nil, options={})
17
+ @tag = series
18
+ end
19
+
20
+ def fetch(start: nil, fin: nil)
21
+ dat = _fetch_data.dup
22
+ hsh = dat.map!{|r| r.to_hash }
23
+ keys = hsh.first.keys
24
+ vals = hsh.map(&:values).transpose
25
+
26
+ df = {}; (0..(keys.length-1)).to_a.each{|i| df[keys[i]] = vals[i]}
27
+
28
+ df = Polars::DataFrame.new(df).drop(['period_duration', 'region_type', 'region_type_id','table_id','is_seasonally_adjusted','region','city','state','state_code', 'parent_metro_region', 'parent_metro_region_metro_code'])
29
+ df = df.filter(Polars.col('period_begin') >= (start.is_a?(Date) ? start : Date.parse(start.to_s))) unless start.nil?
30
+ df = df.filter(Polars.col('period_end') <= (fin.is_a?(Date) ? fin : Date.parse(fin.to_s))) unless fin.nil?
31
+ s = Polars::Series.new('Timestamps', df['period_begin'].to_a)
32
+ df = df.insert_column(0,s)
33
+
34
+ df = (tag.nil? ? df : df.drop(df.columns - ['Timestamps', tag])).sort('Timestamps')
35
+ end
36
+
37
+ protected
38
+
39
+ private
40
+
41
+ def _fetch_data #(options={})
42
+ if @ary.nil?
43
+ tsv_gz = self.class.get('https://redfin-public-data.s3.us-west-2.amazonaws.com/redfin_market_tracker/us_national_market_tracker.tsv000.gz').parsed_response
44
+ tsv = Zlib::GzipReader.new(StringIO.new(tsv_gz)).read
45
+ @ary = CSV.parse(tsv, headers: true, col_sep: "\t", converters: :numeric).select{|a| a['is_seasonally_adjusted'] == 'f'}.each{|r| r['period_begin'] = Date.parse(r['period_begin']); r['period_end'] = Date.parse(r['period_end']) }
46
+ end
47
+ @ary
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module RedfinAsDataframe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -10,13 +10,12 @@ Gem::Specification.new do |spec|
10
10
  spec.description = 'Homeownership and purchase metrics published by Redfin'
11
11
  spec.homepage = "https://github.com/bmck/redfin_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")
14
14
 
15
15
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/bmck/redfin_as_dataframe"
19
- spec.metadata["changelog_uri"] = "https://github.com/bmck/redfin_as_dataframe/CHANGELOG.md"
20
19
 
21
20
  # Specify which files should be added to the gem when it is released.
22
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -29,6 +28,6 @@ Gem::Specification.new do |spec|
29
28
 
30
29
  # Uncomment to register a new dependency of your gem
31
30
  # spec.add_dependency "typhoeus-gem", "~> 0.6.9"
32
- spec.add_dependency 'polars-df'
31
+ spec.add_dependency 'polars-df', '0.27.1'
33
32
  spec.add_dependency 'httparty'
34
33
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redfin_as_dataframe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.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: 2024-08-05 00:00:00.000000000 Z
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: '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
@@ -46,14 +46,17 @@ 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
54
56
  - bin/console
55
57
  - bin/setup
56
58
  - lib/redfin_as_dataframe.rb
59
+ - lib/redfin_as_dataframe/national.rb
57
60
  - lib/redfin_as_dataframe/version.rb
58
61
  - redfin_as_dataframe.gemspec
59
62
  homepage: https://github.com/bmck/redfin_as_dataframe
@@ -62,7 +65,6 @@ licenses:
62
65
  metadata:
63
66
  homepage_uri: https://github.com/bmck/redfin_as_dataframe
64
67
  source_code_uri: https://github.com/bmck/redfin_as_dataframe
65
- changelog_uri: https://github.com/bmck/redfin_as_dataframe/CHANGELOG.md
66
68
  post_install_message:
67
69
  rdoc_options: []
68
70
  require_paths:
@@ -71,14 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
73
  requirements:
72
74
  - - ">="
73
75
  - !ruby/object:Gem::Version
74
- version: 2.3.0
76
+ version: '3.3'
75
77
  required_rubygems_version: !ruby/object:Gem::Requirement
76
78
  requirements:
77
79
  - - ">="
78
80
  - !ruby/object:Gem::Version
79
81
  version: '0'
80
82
  requirements: []
81
- rubygems_version: 3.1.6
83
+ rubygems_version: 3.5.22
82
84
  signing_key:
83
85
  specification_version: 4
84
86
  summary: Home purchase metrics published by Redfin