Skip to content

Commit

Permalink
made pandas a runtime dependecy only, not a build dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mortada committed May 20, 2015
1 parent 9c16b25 commit 156e545
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion fredapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__version__ = '0.3.4'
from fredapi.version import version as __version__
from fredapi.fred import Fred
24 changes: 15 additions & 9 deletions fredapi/fred.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
from urllib import urlencode

import xml.etree.ElementTree as ET
import pandas as pd


class Fred(object):
earliest_realtime_start = '1776-07-04'
latest_realtime_end = '9999-12-31'
nan_char = '.'
max_results_per_request = 1000

def __init__(self,
api_key=None,
api_key_file=None):
Expand Down Expand Up @@ -61,7 +61,8 @@ def _parse(self, date_str, format='%Y-%m-%d'):
"""
helper function for parsing FRED date string into datetime
"""
return pd.to_datetime(date_str, format=format).to_datetime()
from pandas import to_datetime
return to_datetime(date_str, format=format).to_datetime()

def get_series_info(self, series_id):
"""
Expand All @@ -81,7 +82,8 @@ def get_series_info(self, series_id):
root = self.__fetch_data(url)
if root is None:
raise ValueError('No info exists for series id: ' + series_id)
info = pd.Series(root.getchildren()[0].attrib)
from pandas import Series
info = Series(root.getchildren()[0].attrib)
return info

def get_series(self, series_id, observation_start=None, observation_end=None, **kwargs):
Expand All @@ -105,12 +107,13 @@ def get_series(self, series_id, observation_start=None, observation_end=None, **
a Series where each index is the observation date and the value is the data for the Fred series
"""
url = "http://api.stlouisfed.org/fred/series/observations?series_id=%s&api_key=%s" % (series_id, self.api_key)
from pandas import to_datetime, Series

if observation_start is not None:
observation_start = pd.to_datetime(observation_start, errors='raise')
observation_start = to_datetime(observation_start, errors='raise')
url += '&observation_start=' + observation_start.strftime('%Y-%m-%d')
if observation_end is not None:
observation_end = pd.to_datetime(observation_end, errors='raise')
observation_end = to_datetime(observation_end, errors='raise')
url += '&observation_end=' + observation_end.strftime('%Y-%m-%d')

if kwargs is not None:
Expand All @@ -127,7 +130,7 @@ def get_series(self, series_id, observation_start=None, observation_end=None, **
else:
val = float(val)
data[self._parse(child.get('date'))] = val
return pd.Series(data)
return Series(data)

def get_series_latest_release(self, series_id):
"""
Expand Down Expand Up @@ -183,7 +186,8 @@ def get_series_as_of_date(self, series_id, as_of_date):
data : Series
a Series where each index is the observation date and the value is the data for the Fred series
"""
as_of_date = pd.to_datetime(as_of_date)
from pandas import to_datetime
as_of_date = to_datetime(as_of_date)
df = self.get_series_all_releases(series_id)
data = df[df['realtime_start'] <= as_of_date]
return data
Expand Down Expand Up @@ -232,7 +236,8 @@ def get_series_all_releases(self, series_id):
'date': date,
'value': val}
i += 1
data = pd.DataFrame(data).T
from pandas import DataFrame
data = DataFrame(data).T
return data

def get_series_vintage_dates(self, series_id):
Expand Down Expand Up @@ -282,7 +287,8 @@ def __do_series_search(self, url):
data[series_id][field] = child.get(field)

if num_results_returned > 0:
data = pd.DataFrame(data, columns=series_ids).T
from pandas import DataFrame
data = DataFrame(data, columns=series_ids).T
# parse datetime columns
for field in ["realtime_start", "realtime_end", "observation_start", "observation_end", "last_updated"]:
data[field] = data[field].apply(self._parse, format=None)
Expand Down
2 changes: 2 additions & 0 deletions fredapi/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

version = '0.3.4'
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
from setuptools import setup
from fredapi import __version__
from fredapi.version import version as __version__

requires = ['pandas']

Expand All @@ -19,7 +19,6 @@
packages=['fredapi'],
platforms=["Any"],
install_requires=requires,
setup_requires=requires,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
Expand Down

0 comments on commit 156e545

Please sign in to comment.