|
12 | 12 | _URL_SUFFIX = '_CSV.zip'
|
13 | 13 |
|
14 | 14 |
|
15 |
| -def get_available_datasets(): |
| 15 | +def get_available_datasets(**kwargs): |
16 | 16 | """
|
17 | 17 | Get the list of datasets available from the Fama/French data library.
|
18 | 18 |
|
| 19 | + Parameters |
| 20 | + ---------- |
| 21 | + session : Session, default None |
| 22 | + requests.sessions.Session instance to be used |
| 23 | +
|
19 | 24 | Returns
|
20 | 25 | -------
|
21 | 26 | A list of valid inputs for get_data_famafrench.
|
22 | 27 | """
|
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() |
35 | 29 |
|
36 | 30 |
|
37 | 31 | def _parse_date_famafrench(x):
|
@@ -128,3 +122,24 @@ def _read_one_data(self, url, params):
|
128 | 122 | datasets['DESCR'] = descr + '\n'.join(table_descr)
|
129 | 123 |
|
130 | 124 | 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