Skip to content

ENH: Add session parameter to get_available_datasets #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ENH: Add session parameter to get_available_datasets
  • Loading branch information
femtotrader committed Dec 10, 2015
commit c428c6ade91e8e66a06888ef5027d529d1811361
41 changes: 28 additions & 13 deletions pandas_datareader/famafrench.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,20 @@
_URL_SUFFIX = '_CSV.zip'


def get_available_datasets():
def get_available_datasets(**kwargs):
"""
Get the list of datasets available from the Fama/French data library.

Parameters
----------
session : Session, default None
requests.sessions.Session instance to be used

Returns
-------
A list of valid inputs for get_data_famafrench.
"""
try:
from lxml.html import parse
except ImportError:
raise ImportError("Please install lxml if you want to use the "
"get_datasets_famafrench function")

root = parse(_URL + 'data_library.html')

l = filter(lambda x: x.startswith(_URL_PREFIX) and x.endswith(_URL_SUFFIX),
[e.attrib['href'] for e in root.findall('.//a') if 'href' in e.attrib])

return lmap(lambda x: x[len(_URL_PREFIX):-len(_URL_SUFFIX)], l)
return FamaFrenchReader(symbols='', **kwargs).get_available_datasets()


def _parse_date_famafrench(x):
Expand Down Expand Up @@ -128,3 +122,24 @@ def _read_one_data(self, url, params):
datasets['DESCR'] = descr + '\n'.join(table_descr)

return datasets

def get_available_datasets(self):
"""
Get the list of datasets available from the Fama/French data library.
Returns
-------
A list of valid inputs for get_data_famafrench.
"""
try:
from lxml.html import document_fromstring
except ImportError:
raise ImportError("Please install lxml if you want to use the "
"get_datasets_famafrench function")

response = self.session.get(_URL + 'data_library.html')
root = document_fromstring(response.content)

l = filter(lambda x: x.startswith(_URL_PREFIX) and x.endswith(_URL_SUFFIX),
[e.attrib['href'] for e in root.findall('.//a') if 'href' in e.attrib])

return lmap(lambda x: x[len(_URL_PREFIX):-len(_URL_SUFFIX)], l)