Skip to content

Commit

Permalink
Merge pull request #49 from mortada/realtime-start-end-args
Browse files Browse the repository at this point in the history
add optional realtime_start/end arguments to get_series_all_releases()
  • Loading branch information
mortada authored Mar 15, 2022
2 parents 4f2b135 + e0bf596 commit 8a6beb9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 12 additions & 4 deletions fredapi/fred.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
HTTPError = url_error.HTTPError


class Fred(object):
class Fred:
earliest_realtime_start = '1776-07-04'
latest_realtime_end = '9999-12-31'
nan_char = '.'
Expand Down Expand Up @@ -200,7 +200,7 @@ def get_series_as_of_date(self, series_id, as_of_date):
data = df[df['realtime_start'] <= as_of_date]
return data

def get_series_all_releases(self, series_id):
def get_series_all_releases(self, series_id, realtime_start=None, realtime_end=None):
"""
Get all data for a Fred series id including first releases and all revisions. This returns a DataFrame
with three columns: 'date', 'realtime_start', and 'value'. For instance, the US GDP for Q4 2013 was first released
Expand All @@ -213,17 +213,25 @@ def get_series_all_releases(self, series_id):
----------
series_id : str
Fred series id such as 'GDP'
realtime_start : str, optional
specifies the realtime_start value used in the query, defaults to the earliest possible start date allowed by Fred
realtime_end : str, optional
specifies the realtime_end value used in the query, defaults to the latest possible end date allowed by Fred
Returns
-------
data : DataFrame
a DataFrame with columns 'date', 'realtime_start' and 'value' where 'date' is the observation period and 'realtime_start'
is when the corresponding value (either first release or revision) is reported.
"""
if realtime_start is None:
realtime_start = self.earliest_realtime_start
if realtime_end is None:
realtime_end = self.latest_realtime_end
url = "%s/series/observations?series_id=%s&realtime_start=%s&realtime_end=%s" % (self.root_url,
series_id,
self.earliest_realtime_start,
self.latest_realtime_end)
realtime_start,
realtime_end)
root = self.__fetch_data(url)
if root is None:
raise ValueError('No data exists for series id: ' + series_id)
Expand Down
6 changes: 1 addition & 5 deletions fredapi/tests/test_fred.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
if sys.version_info[0] >= 3:
unicode = str

import os
import io
import unittest
if sys.version_info < (3, 3):
import mock # pylint: disable=import-error
else:
from unittest import mock # pylint: disable=import-error
import datetime as dt
import textwrap
import contextlib
import pandas as pd
import fredapi
import fredapi.fred

Expand All @@ -27,7 +23,7 @@
fred_api_key = fredapi.Fred().api_key


class HTTPCall(object):
class HTTPCall:
"""Encapsulates faked Fred call data."""

root_url = fredapi.Fred.root_url
Expand Down
2 changes: 1 addition & 1 deletion fredapi/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

version = '0.4.3'
version = '0.5.0'

0 comments on commit 8a6beb9

Please sign in to comment.