Skip to content

Commit 6945e3a

Browse files
Merge pull request #141 from femtotrader/famafrench_session
ENH: Add session parameter to get_available_datasets
2 parents 084e4ee + c428c6a commit 6945e3a

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

pandas_datareader/famafrench.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,20 @@
1212
_URL_SUFFIX = '_CSV.zip'
1313

1414

15-
def get_available_datasets():
15+
def get_available_datasets(**kwargs):
1616
"""
1717
Get the list of datasets available from the Fama/French data library.
1818
19+
Parameters
20+
----------
21+
session : Session, default None
22+
requests.sessions.Session instance to be used
23+
1924
Returns
2025
-------
2126
A list of valid inputs for get_data_famafrench.
2227
"""
23-
try:
24-
from lxml.html import parse
25-
except ImportError:
26-
raise ImportError("Please install lxml if you want to use the "
27-
"get_datasets_famafrench function")
28-
29-
root = parse(_URL + 'data_library.html')
30-
31-
l = filter(lambda x: x.startswith(_URL_PREFIX) and x.endswith(_URL_SUFFIX),
32-
[e.attrib['href'] for e in root.findall('.//a') if 'href' in e.attrib])
33-
34-
return lmap(lambda x: x[len(_URL_PREFIX):-len(_URL_SUFFIX)], l)
28+
return FamaFrenchReader(symbols='', **kwargs).get_available_datasets()
3529

3630

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

130124
return datasets
125+
126+
def get_available_datasets(self):
127+
"""
128+
Get the list of datasets available from the Fama/French data library.
129+
Returns
130+
-------
131+
A list of valid inputs for get_data_famafrench.
132+
"""
133+
try:
134+
from lxml.html import document_fromstring
135+
except ImportError:
136+
raise ImportError("Please install lxml if you want to use the "
137+
"get_datasets_famafrench function")
138+
139+
response = self.session.get(_URL + 'data_library.html')
140+
root = document_fromstring(response.content)
141+
142+
l = filter(lambda x: x.startswith(_URL_PREFIX) and x.endswith(_URL_SUFFIX),
143+
[e.attrib['href'] for e in root.findall('.//a') if 'href' in e.attrib])
144+
145+
return lmap(lambda x: x[len(_URL_PREFIX):-len(_URL_SUFFIX)], l)

0 commit comments

Comments
 (0)