File tree Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -595,15 +595,18 @@ def get_datasets_famafrench():
595
595
-------
596
596
A list of valid inputs for get_data_famafrench.
597
597
"""
598
- from bs4 import BeautifulSoup
598
+ try :
599
+ from lxml .html import parse
600
+ except ImportError :
601
+ raise ImportError ("Please install lxml if you want to use the "
602
+ "get_datasets_famafrench function" )
599
603
600
- with urlopen (_FAMAFRENCH_URL + 'data_library.html' ) as socket :
601
- root = BeautifulSoup (socket .read (), 'html.parser' )
604
+ root = parse (_FAMAFRENCH_URL + 'data_library.html' )
602
605
603
606
l = filter (lambda x : x .startswith (_FF_PREFIX ) and x .endswith (_FF_SUFFIX ),
604
- [e .attrs ['href' ] for e in root .findAll ( ' a' ) if 'href' in e .attrs ])
607
+ [e .attrib ['href' ] for e in root .findall ( '.// a' ) if 'href' in e .attrib ])
605
608
606
- return list ( map ( lambda x : x [len (_FF_PREFIX ):- len (_FF_SUFFIX )], l ) )
609
+ return lmap ( lambda x : x [len (_FF_PREFIX ):- len (_FF_SUFFIX )], l )
607
610
608
611
609
612
def _download_data_famafrench (name ):
@@ -621,7 +624,6 @@ def _download_data_famafrench(name):
621
624
622
625
623
626
def _parse_date_famafrench (x ):
624
- # what's the correct python way to do that ??
625
627
x = x .strip ()
626
628
try : return dt .datetime .strptime (x , '%Y' )
627
629
except : pass
Original file line number Diff line number Diff line change 3
3
4
4
import pandas_datareader .data as web
5
5
6
- def _skip_if_no_bs4 ():
7
- try :
8
- import bs4
9
- except ImportError :
10
- raise nose .SkipTest ('no bs4' )
11
-
12
6
13
7
class TestFamaFrench (tm .TestCase ):
14
8
def test_read_famafrench (self ):
@@ -23,7 +17,7 @@ def test_read_famafrench(self):
23
17
assert len (ff ) > 1
24
18
25
19
def test_get_datasets (self ):
26
- _skip_if_no_bs4 ()
20
+ # _skip_if_no_lxml ()
27
21
l = web .get_datasets_famafrench ()
28
22
assert len (l ) > 100
29
23
You can’t perform that action at this time.
0 commit comments