Skip to content

Add session parameter to get_available_datasets #136

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pandas_datareader/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class RemoteDataError(PandasError, IOError):
if PANDAS_VERSION >= LooseVersion('0.14.0'):
PANDAS_0140 = True
else:
PANDAS_0140 = False
PANDAS_0140 = False
43 changes: 28 additions & 15 deletions pandas_datareader/famafrench.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,18 @@
_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):
x = x.strip()
Expand Down Expand Up @@ -128,3 +119,25 @@ 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)